压缩为 GZip WCF 请求(SOAP 和 REST)

发布于 2024-08-31 07:08:49 字数 503 浏览 0 评论 0原文

我有一个托管在 Windows Azure 上的 .NET 3.5 Web 应用程序,它公开了多个 WCF 端点(SOAP 和 REST)。端点通常接收比它们提供的数据多100倍(上传的数据较多,下载的数据少得多)。

因此,我愿意利用 HTTP GZip 压缩,但不是从服务器的角度来看,而是从客户端的角度来看,发送压缩请求(返回压缩响应就可以了,但无论如何不会带来太多收益)。

以下是客户端用于激活 WCF 的小 C# 代码片段:

var binding = new BasicHttpBinding();
var address = new EndpointAddress(endPoint);

_factory = new ChannelFactory<IMyApi>(binding, address);
_channel = _factory.CreateChannel(); 

知道如何调整行为以便可以发出压缩的 HTTP 请求吗?

I have a .NET 3.5 web app hosted on Windows Azure that exposes several WCF endpoints (both SOAP and REST). The endpoints typically receive 100x more data than they serve (lot of data is upload, much fewer is downloaded).

Hence, I am willing to take advantage from HTTP GZip compression but not from the server viewpoint, but rather from the client viewpoint, sending compressed requests (returning compressed responses would be fine, but won't bring much gain anyway).

Here is the little C# snippet used on the client side to activate WCF:

var binding = new BasicHttpBinding();
var address = new EndpointAddress(endPoint);

_factory = new ChannelFactory<IMyApi>(binding, address);
_channel = _factory.CreateChannel(); 

Any idea how to adjust the behavior so that compressed HTTP requests can be made?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上芳菲 2024-09-07 07:08:49

如果您想使用商业组件,请尝试这个。它为请求和响应提供基于标准的 HTTP 压缩。我不确定Azure是否支持解压缩压缩请求,如果不支持,那么您也可以在Azure上使用它来提供解压缩。这是根据需要修改的绑定:

using Noemax.WCFX.Channels;

var binding = new BasicHttpBinding();
var address = new EndpointAddress(endPoint);

ContentNegotiationBindingElement contentNegotiation = new ContentNegotiationBindingElement();
contentNegotiation.CompressionMode = SmartCompressionMode.Optimistic;

binding = contentNegotiation.PlugIn(binding);

_factory = new ChannelFactory<IMyApi>(binding, address);
_channel = _factory.CreateChannel(); 

If you would like to use a commercial component then try this. It provides standard-based HTTP compression for both requests and responses. I am not sure whether Azure supports decompressing compressed requests, if it doesn't then you can also use it on Azure to provide decompression. Here is your binding modified as needed:

using Noemax.WCFX.Channels;

var binding = new BasicHttpBinding();
var address = new EndpointAddress(endPoint);

ContentNegotiationBindingElement contentNegotiation = new ContentNegotiationBindingElement();
contentNegotiation.CompressionMode = SmartCompressionMode.Optimistic;

binding = contentNegotiation.PlugIn(binding);

_factory = new ChannelFactory<IMyApi>(binding, address);
_channel = _factory.CreateChannel(); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文