使用basicHttpBinding的WCF服务仍然发送内容类型"text/xml"

Jef*_*ege 6 wcf soap

我正在编写一个在IIS上运行的WCF服务,我有一个客户,其客户端只能与SOAP 1.1交谈.

除此之外,他们需要内容类型为"application/soap + xml; charset = utf-8".我的WCF服务正在发送"text/xml; charset = utf-8".

正在尝试编写客户端的客户转发了一条错误消息:

HTTP 415:无法处理消息,因为内容类型为'text/xml; charset = utf-8'不是预期的类型'application/soap + xml; 字符集= utf-8的

浏览网络时,我发现了许多类似的博客页面:WCF错误 - 请求因HTTP状态415而失败.

这让我觉得从wsHttpBinding切换到basicHttpBinding会解决这个问题.所以我更改了web.config中的绑定,并修改了我自己的测试客户端,以显式创建一个带有BasicHttpBinding的端点.这一切都运行良好,在我自己的测试中(在Visual Studio的Dev Server中运行服务,在我自己的机器上的IIS7中运行它,并在我们的一个测试服务器上的IIS6中运行它.)

但在我向顾客提出要求之前,让他们看看我的改变是否会对他们起作用之前,我向Fiddler开火,以窃听实际的流量.

据Fiddler说,我还在发送"text/xml; charset = utf-8".

那么,我该如何解决这个问题呢?

<system.serviceModel>
    <services>
        <service behaviorConfiguration="myBehavior" name="myName">
            <endpoint 
                    address=""
                    binding="basicHttpBinding" 
                    behaviorConfiguration="flatWsdlFileEndpointBehavior" 
                    bindingNamespace="http://myNamespace"
                    contract="myContract">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="myBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="flatWsdlFileEndpointBehavior">
                <wsdlExtensions location="myUrl" singleFile="true" />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
        </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <extensions>
        <behaviorExtensions>
            <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        </behaviorExtensions>
    </extensions>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

Lad*_*nka 13

那么他们需要SOAP 1.1还是application/soap+xml; charset=utf-8?因为SOAP 1.1规范说请求必须具有text/xml媒体类型.application/soap+xml是SOAP 1.2的媒体类型.强制WCF使用带有application/soap+xml(=无效SOAP)的SOAP 1.1 需要比更改绑定更大的更改.您将需要一些自定义消息编码器或传输通道.

  • 请注意,wsHttpBinding使用SOAP 1.2 (2认同)