2013-10-01 80 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的請求。 –