我可能错过了显而易见的问题,但是如何才能使我的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>
答案 0 :(得分: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
部分