加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

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

发布时间:2020-12-14 23:27:44 所属栏目:资源 来源:网络整理
导读:我正在编写一个在IIS上运行的WCF服务,我有一个客户,其客户端只能与SOAP 1.1交谈. 除此之外,他们需要内容类型为“application / soap xml; charset = utf-8”.我的WCF服务正在发送“text / xml; charset = utf-8”. 正在尝试编写客户端的客户转发了一条错误消
我正在编写一个在IIS上运行的WCF服务,我有一个客户,其客户端只能与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中的绑定,并修改了我自己的测试客户端,以显式创建一个带有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>

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读