WCF REST(与WebHttpBinding兼容)客户端gzip压缩-从服务器解压缩Web响应

问题描述:



我一直在寻找一种方法,以向基于WebHttpBinding的客户端WCF REST Web服务接口中添加新行为.

我具有Java EE服务器,该服务器具有gzip(正常压缩强度)功能以进行响应.通常,这是内容协商".但是为了进行测试,我可以为所有响应(碰巧是XML文档)永久打开它.

我尝试了几种建议的将解压缩功能添加到客户端WCF的方法,但我遇到了几种方法之一问题.我尝试过的一些解决方案似乎与SOAP WS.*服务兼容,因此当与我的Web REST服务定义混合使用时,在创建服务通道时会导致运行时错误.

我基于添加WcfExtensions.ServiceModel.Channels.CompressionBindingElement

的最后一个解决方案,当我尝试使用此方法时,如果我调整Java EE服务器不压缩响应,则服务调用将从客户端开始.当我启用响应压缩时,出现以下形式的错误:"EndpointNotFoundException"

我对WCF并不十分熟悉,而REST支持方面的文档似乎实在有些薄

如果有人甚至可以确认可以做到这一点,并向我指出应该起作用的代码示例,那么我可能可以做剩下的事情(没有双关语)-目前,我不确定WCF框架中哪些是不可能的限制,哪些是我的测试代码中设置的错误或不正确.理想情况下,我想要一个与标准gzip Web服务器压缩兼容的解决方案,通常也受Web浏览器的支持,等等.

预先感谢您的帮助! :)

Hi,

I've been searching for a little while for a way to add a new behaviour to my client WebHttpBinding based WCF REST web service interface.

I have a Java EE server with gzip (normal compression strength) capability for responses. Normally this is "content negotiated" but for testing I can turn it on permanently for all responses (which happent to be XML documents).

I've tried several suggested methods of adding decompression to the client side WCF and I hit one of several problems. A few of the solutions I've tried seem to be compatible with SOAP WS.* servces, so when mixed with my web REST service definition cause a run time error when the service channel is being created.

The last solution I have based on adding the WcfExtensions.ServiceModel.Channels.CompressionBindingElement

When I try with this, if I adjust my Java EE server not to compress responses the service calls work from the client. When I enable compression of responses I get an error of the form: "EndpointNotFoundException"

I'm not massively familiar with WCF and the documentation on the REST support seems a little thin on the ground when it comes to customisations.

If someone can even confirm this can be done and point me at a sample of code that should work, I can probably do the rest (no pun intended) - at the moment I'm not sure what are impossible limitiations in the WCF framework and what are mistakes or incorrect set up in my test code. Ideally I'd like a solution that's compatible with standard gzip web server compression, as is normally support by web browsers too etc.

thanks for any help in advance! :)

我没有看到自定义消息编码器在这种情况下不起作用的任何原因,您是否尝试过样本GZIP编码器? http://msdn.microsoft.com/en-us/library/ms751458.aspx

构造自定义绑定也很重要(您需要使用新的编码器替换WebHttpBinding中的TextMessageEncodingBindingElement,请参见

I don't see any reason why a custom message encoder shouldn't work in this situation, have you tried the sample GZIP encoder? http://msdn.microsoft.com/en-us/library/ms751458.aspx

It also matters how you construct the custom binding (you need to replace the TextMessageEncodingBindingElement in WebHttpBinding with the new encoder, see http://social.msdn.microsoft.com/forums/en-US/wcf/thread/beb10532-33f8-4cff-ba2d-99641775add1/ for an example of this, although you won't be wrapping the encoder in this case)