我可能错过了显而易见的事情,但是我怎样才能使我的 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>