我正在构建一个需要与非WCF客户端交互的WCF Web服务(事实上,将不会有WCF客户端)。
我已经使用SOAP 1.2(as per this example)编写了一个WSDL。我已经验证了WSDL,并且使用了这个文件(而不是由WCF生成的WSDL,这在表面上是不同的)创建了一个soapUI测试项目。
我有一个要求,Web服务将支持SOAP 1.2,所以我不能只是回到SOAP 1.1(在早期的原型中工作得很好)。
我使用WSCF.blue来生成我的WCF服务,接口和数据契约类。一切都很好地编译,如果我在浏览器中点击了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规定内容类型必须是text / xml。 SOAP 1.2需要application / 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"
xmlns:ns="http://tempuri.org">
从这个响应中,它告诉我,我的请求是正确的 – 它是一个具有正确内容类型的SOAP 1.2请求。然而,我的WCF服务并不期望这种内容类型,我认为这意味着我没有正确配置它,它仍然认为它是一个SOAP 1.1 Web服务。
Minimal Web.config,根据this blog post:
服务合同的片段:
[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
System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
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.
(erroneous detail snipped)
所以,我的合同和服务绑定可能是不匹配的,如果这个消息是相信的,但是从我对WCF的了解我的配置(或至少其背后的意图)是正确的。
有没有人有任何想法,我的配置有什么问题?