gpt4 book ai didi

WCF SOAP 1.2 服务需要 SOAP 1.1 内容类型

转载 作者:行者123 更新时间:2023-12-03 11:58:56 28 4
gpt4 key购买 nike

我正在构建一个需要与非 WCF 客户端互操作的 WCF Web 服务(事实上,不会有 WCF 客户端)。

我已经使用 SOAP 1.2 (as per this example) 编写了一个 WSDL。我已经验证了 WSDL 并使用了这个文件(不是 WCF 生成的 WSDL,表面上有所不同)来创建一个 soapUI测试项目。

我的要求是 Web 服务将支持 SOAP 1.2,所以我不能只是退回到 SOAP 1.1(它在早期原型(prototype)中工作得很好)。

我用过WSCF.blue生成我的 WCF 服务、接口(interface)和数据协定类。如果我在浏览器中点击 WCF 服务,一切都编译得很好,并且端点会暴露出来。世界上一切似乎都很好。

当我尝试从 soapUi 调用方法时,我从服务器得到以下响应(从 soapUI 可见):

HTTP/1.1 415 Cannot process the message because the content type 
'application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing"'
was not the expected type 'text/xml; charset=utf-8'.
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 30 Apr 2012 08:15:29 GMT
Content-Length: 0

(为了这个问题的目的,实际的方法名称和命名空间已经手动更改。命名空间中的任何拼写错误都不是我的代码中的错误 - 只是输入这个问题时的疏忽)

我知道 SOAP 1.1 指定内容类型必须是 文本/xml . SOAP 1.2 需要 应用程序/soap+xml .

我的原始请求(根据soapUI):
POST http://localhost/MyWs.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing"

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns="http://tempuri.org">
<soap:Header/>
<soap:Body>
<ns:fetchMyThingRequest attribute1="1" attribute2="10">
</ns:fetchMyThingRequest>
</soap:Body>
</soap:Envelope>

从这个响应中,它告诉我我的请求格式正确——它是一个内容类型正确的 SOAP 1.2 请求。然而,我的 WCF 服务并不期望这种内容类型,我认为这意味着我没有正确配置它,它仍然认为它是一个 SOAP 1.1 Web 服务。

最小的 Web.config,根据 this blog post :
<system.serviceModel>
<services>
<service name="MyNamespace.MyPort">
<endpoint address="" binding="customBinding" bindingConfiguration="httpSoap12" contract="IWsPort12" />
</service>
</services>

<bindings>
<customBinding>
<binding name="httpSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
</system.serviceModel>

服务契约(Contract)的片段:
[ServiceContract(Namespace = "http://tempuri.org")]
public interface IWsPort
{
[OperationContract(Action = "http://tempuri.org/FetchMyThing")]
[FaultContract(typeof(WsFault), Action = "http://tempuri.org/FetchMyThing", Name = "fetchMyThingFault")]
[XmlSerializerFormat(SupportFaults = true)]
FetchMyThingResponse FetchMyThing(FetchMyThingRequest request);
}

我为我的 WCF 服务启用了服务跟踪,并看到以下异常似乎证实了我的假设:
Activity: Listen at 'http://mycomputer/MyWs.svc
<Exception>
<ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Content Type application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing" was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.
</Message>
(erroneous detail snipped)
</Exception>

因此,如果要相信此消息,我的契约(Contract)和服务绑定(bind)可能不匹配,但根据我对 WCF 的理解,我的配置(或至少其背后的意图)是正确的。

有人对我的配置有什么问题有任何想法吗?

最佳答案

我唯一能想到的是,因为您没有详细指定绑定(bind),并且它使用 HTTP(根据此:“Listen at 'http://mycomputer/MyWs.svc'”)然后它使用默认值(即 basicHttpBinding )为此,这是造成不匹配?

关于WCF SOAP 1.2 服务需要 SOAP 1.1 内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10403806/

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