簡體   English   中英

WCF服務接受GZip消息

[英]WCF Service Accepting GZip Messages

我可能缺少明顯的東西,但是如何使它成為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>

在IIS上托管服務時,無需對.NET 4+進行任何特殊處理。 您只需要在IIS上啟用HTTP壓縮即可。

有關如何在IIS 7中啟用HTTP壓縮的鏈接,請查看WCF 4新增功能中有關Http解壓縮的部分。

在WCF 4.5中,您還獲得了對二進制編碼器的壓縮支持。 檢查“ 壓縮和二進制編碼器”部分

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM