GZIP压缩请求通过WCF远程Web服务 [英] GZIP compress the request to a remote web service via WCF

查看:199
本文介绍了GZIP压缩请求通过WCF远程Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写使用需要与远程Web服务进行通信的Visual Studio 2010的应用程序。由于提交的数据量可能非常大,(可达100MB),该服务的文件说,请求消息必须使用GZIP HTTP压缩发送。

I'm writing an application using Visual Studio 2010 that needs to communicate with a remote web service. Because the amount of data being submitted is potentially large, (up to 100MB), the service's documentation says that the request message must be sent using GZIP HTTP compression.

我的问题如何做到这一点,因为我只是调用代理对象的方法生成的Visual Studio,并没有实际执行POST自己?换句话说,因为没有一个请求在我的代码,以GZIP任何地方,我怎么能告诉WCF来为我做的?

My question is how to do that, given that I'm just calling a method on the proxy object that Visual Studio generated, and not actually performing the POST myself? In other words, since there isn't a "request" anywhere in my code to GZIP, how can I tell WCF to do it for me?

我已经连通过使用提供的WSDL添加一个服务引用我的应用程序,然后在Visual Studio中调用一个方法的服务生成的代理提交请求。一个例外是抛出消息请求消息必须使用HTTP压缩发送。 (这不是意外的,当然。)

I've connected to the service by adding a service reference to my application using the WSDL provided, then invoking a method on the Visual Studio generated proxy to submit the request. An exception is thrown with the message "Request message must be sent using HTTP compression." (This is not unexpected, of course.)

是否有定义WCF服务,将导致WCF以发送到远程主机之前GZIP请求的web.config设置中的属性。

Is there an attribute within the web.config settings that define the WCF service that will cause WCF to GZIP the request before sending it to the remote host?

请注意:我'已经花显著时间来搜索这个网站,但问题是,大多数的帖子认为它是Web服务的响应需要被压缩。在我的情况,但是,它在要求就是正从我的客户端发送。

Note: I've spent significant time searching the web about this, but the problem is that most posts assume that it's the web service's response that needs to be compressed. In my case, however, it's the request that's being sent from my client.

推荐答案

好像我已经能够解决这个问题的方式,是没有意义的我从一个为什么这甚至还存在的方式。

It seems like I have been able resolve this issue in a way that makes no sense to me from a "why does this even exist" way.

首先,我在做相同的任务你:尝试使用代理对象来创建一个Web请求,并最终运行到同一个问题是无法压缩的客户对象

First, I was working on the same task as you: trying to use proxy objects to create a web request, and ended up running into the same issue being unable to compress the client object.

我结束了被手动创建XDocument对象的分辨率(XmlDocument的将工作以及)具有相同的结构所需的SOAP XML,然后使用(已)填充代理对象来填充必要XML值在SOAP的XML字符串。

The resolution I ended up with was manually creating an XDocument object (XmlDocument would work as well) which has the same structure as the required SOAP XML, and then used the (already) populated proxy object to populate the necessary XML values in the string of SOAP XML.

从那里我做了一个的HttpWebRequest 对象,并添加相应的头文件的请求。一标题的是压缩。执行代码导致得到一个完全不同的,非压缩相关的,错误。

From there I made a HttpWebRequest object and added the appropriate headers to the request. One of the headers was for compression. Executing the code resulted in getting an entirely different, non-compression related, error.

您可以看到我的的HttpWebRequest 在这里:压缩HttpWebRequest的使用gzip

You can see my solution for the HttpWebRequest here: Compress a HttpWebRequest using gzip

看来愚蠢,这是不容易通过这个代理对象做;但是,它可能是第三方没有暴露什么,以属性添加到请求标头是必要的或者是。)他们不知道或b)。他们不在乎,但是这就是我们所拥有的有,可惜工作。

It seems silly that it isn't easy to do through this the proxy object; however, it may be that the third-party did not expose what is necessary in order to add properties to the request header and either a.) they don't know or b.) they don't care, but that's what we have to work with, unfortunately.

我必须想办法的,因为我的最后期限,但我希望这可以帮助你为好。

I had to figure something out as I am on a deadline, but I hope this helps you out as well.

这篇关于GZIP压缩请求通过WCF远程Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆