2013-10-01 49 views
2

我可能错过了明显的,但我怎么能使它,以便我的WCF服务上的一个方法,PutMessage,可以接受GZip'd和正常请求?现在,我从我的服务看到此错误:WCF服务接受GZip消息

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

我已经尝试添加自定义与binaryMessageCoding/compressionFormat =“压缩”和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> 

回答

0

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

查看What's New in WCF 4中关于Http Decompression的部分,了解关于如何使用enable HTTP compression in IIS 7的一些链接。

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

+0

我认为这可能是我困惑的地方。 IIS设置似乎围绕GZip *响应*,而不是*请求*。 – MattGWagner

+0

我确保在IIS上启用压缩,并将*/*作为启用的动态类型,但错误仍在发生。 – MattGWagner

+0

请求由客户端生成,而不是服务生成。客户需要创建一个使用GZip的请求。 –