如何在 WCF 中处理来自 SoapUI 的 gzip?

How to process gzip from SoapUI in WCF?

我正在我的 WCF 中进行两种方式的 gzip 压缩。 IIS 的响应部分相当容易,但我似乎无法使用 SoapUI 处理请求。我使用 SoapUI 的原因是因为要连接的客户端应用程序不会在其端使用 Microsoft 堆栈。

我在这里创建了一个示例解决方案来演示问题 https://github.com/janmchan/WCFCompression

在解决方案中,我有一个 WCFServiceDemo(WCF 服务器)和 WCFClient(WCF 客户端)。对客户端/服务器使用下面的绑定,我对请求/响应没有任何问题。

<bindings>
  <customBinding>
    <binding name="myBinding">
      <binaryMessageEncoding compressionFormat="GZip"/>
      <httpTransport decompressionEnabled="True" />
    </binding>
  </customBinding>
</bindings>

通过此请求我得到以下 header

2016-05-23 11:37;14 : Connection: Keep-Alive
Content-Length: 298
Content-Type: application/soap+msbin1+gzip
Accept-Encoding: gzip, deflate
Expect: 100-continue
Host: localhost:19860

但是,使用具有这些设置的 SoapUI

和这条示例消息

我收到以下回复,提示内容类型不正确。我试过添加 headers 但它似乎不是解决方案。我也尝试添加一个模块来添加Gzip压缩的过滤器,但是在退出所有模块后它仍然遇到错误。

如何确保终端客户端可以像 SoapUI 的连接方式一样连接到 WCF?

HTTP/1.1 415 Cannot process the message because the content type 'application/soap+xml;charset=UTF-8;action="http://tempuri.org/IService1/GetData"' was not the expected type 'application/soap+msbin1+gzip' Cache-Control: private
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?YzpcdXNlcnNcamNoYW5cZG9jdW1lbnRzXHZpc3VhbCBzdHVkaW8gMjAxNVxQcm9qZWN0c1xXY2ZTZXJ2aWNlRGVtb1xXY2ZTZXJ2aWNlRGVtb1xTZXJ2aWNlMS5zdmM=?=
X-Powered-By: ASP.NET
Date: Tue, 24 May 2016 00:04:19 GMT
Connection: close
Content-Length: 0

在经历了几个选项之后,我发现解决这个问题的最好方法是使用自定义 MessageEncoder。虽然我有一个工作示例 here,但我仍然遇到一些 headers 丢失的问题,但基本上当这个问题得到解决时,它应该是这个问题的解决方案。

Why are the soap headers missing when using Custom MessageEncoder