【问题标题】:WCF Service Accepting GZip MessagesWCF 服务接受 GZip 消息
【发布时间】:2013-10-01 15:24:15
【问题描述】:

我可能错过了显而易见的事情,但是我怎样才能使我的 WCF 服务上的一种方法 PutMessage 可以同时接受 GZip 和正常请求?现在我从我的服务中看到了这个错误:

Cannot process the message because the content type 'application/gzip' was not the expected type 'text/xml; charset=utf-8'.

我尝试使用 binaryMessageCoding/compressionFormat="GZip" 和 httpTransport 添加自定义绑定。这是否需要配置多个绑定和多个端点?还是多个绑定和一个端点?一个端点和一个绑定?

我无法更改发送代码,因为它是我无权访问的第三方。

到目前为止,这是我的 Web.config:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="UserNameAuthenticationBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="API.Star.XXXUsernamePasswordValidator, API" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="API.Star.starTransport">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="Basic" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </basicHttpBinding>
      <customBinding>
        <binding name="API.Star.starTransportGzip">
          <binaryMessageEncoding compressionFormat="GZip" />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="API.Star.StarWebService" behaviorConfiguration="UserNameAuthenticationBehaviour">
        <endpoint name="StarWebServiceEndpoint" address="" binding="basicHttpBinding" bindingConfiguration="API.Star.starTransport" contract="API.Star.operations" bindingNamespace="http://www.starstandards.org/webservices/2005/10/transport" />
        <endpoint name="StarWebServiceEndpointGzip" address="" binding="customBinding" bindingConfiguration="API.Star.starTransportGzip" contract="API.Star.operations" bindingNamespace="http://www.starstandards.org/webservices/2005/10/transport" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    当您在 IIS 上托管您的服务时,您不需要为 .NET 4+ 做任何特别的事情。您只需在 IIS 上启用 HTTP 压缩。

    查看What's New in WCF 4 中有关 Http 解压的部分以获取有关如何使用enable HTTP compression in IIS 7 的链接。

    在 WCF 4.5 中,您还可以获得对二进制编码器的压缩支持。查看Compression and the Binary Encoder部分

    【讨论】:

    • 我认为这可能是我感到困惑的地方。 IIS 设置似乎围绕 GZip responses,而不是 requests
    • 我确保在 IIS 上启用了压缩并将 / 作为启用的动态类型包含在内,但错误仍然存​​在。
    • 请求由客户端生成,而不是服务生成。由客户端创建使用 GZip 的请求。
    • 客户端正在使用 GZip 处理一些请求——错误表明服务不会接受它。
    • 只有在您拥有 .NET 客户端时才适用。但是,如果您的源是示例 SOAPUI,则它不能开箱即用。
    猜你喜欢
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    相关资源
    最近更新 更多