gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:34:14 24 4
gpt4 key购买 nike

我正在编写一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com