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

标签 wcf soap

我正在编写一个 WCF 服务,在 IIS 上运行,我有一个客户的客户只能使用 SOAP 1.1。

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

试图写客户端的客户向我转发了一条错误消息:

HTTP 415: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8



在网上浏览,我发现了许多这样的博客页面:WCF Error - The request failed with HTTP status 415 .

这让我觉得从 wsHttpBinding 切换到 basicHttpBinding 可以解决这个问题。所以我更改了 web.config 中的绑定(bind),并修改了我自己的测试客户端以显式创建一个带有 BasicHttpBinding 的端点。在我自己的测试中,这一切都运行良好(在 Visual Studio 的开发服务器中运行服务,在我自己的机器上的 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>

最佳答案

他们是否需要 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 1.1 (= 无效的 SOAP)将需要比更改绑定(bind)更大的更改。您将需要一些自定义消息编码器或传输 channel 。

关于使用 basicHttpBinding 的 WCF 服务仍在发送内容类型 "text/xml",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8087515/

相关文章:

c# stream wcf上传文件

wcf - 自承载 WCF 数据服务上的 Kerberos 身份验证

java - 使用QuickBooks Web Connector的身份验证问题:对象引用未设置为对象的实例

web-services - 贾克斯WS : Externalize Http Conduit name Attribute

java - 解码具有多个同名元素的 XML JAXB

python-2.7 - 添加 CustomTransport 时忽略 SUDS header

wcf - 如何使用 WCF 签署 X509 token

wcf - 通过 VBScript 调用 WCF 服务

wcf - basichhtpbinding 的哪种身份验证模式可用于保护使用流的 WCF 服务?

使用带 key 的 HTTPS 连接的 Python SOAP 客户端库