我正在构建一个WCF Web服务,需要与非WCF客户端互操作(实际上,没有WCF客户端).
我已经使用SOAP 1.2编写了一个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
Run Code Online (Sandbox Code Playgroud)
(出于此问题的目的,已经手动更改了实际的方法名称和命名空间.命名空间中的任何拼写错误都不是我的代码中的错误 - 只是在输入此问题时的疏忽)
我知道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"
<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>
Run Code Online (Sandbox Code Playgroud)
从这个响应中,它告诉我我的请求是正确形成的 - 它是一个具有正确内容类型的SOAP 1.2请求.但是,我的WCF服务不期望这种内容类型,我认为这意味着我没有正确配置它,它仍然认为它是一个SOAP 1.1 Web服务.
最小的Web.config,根据这篇博文:
<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>
Run Code Online (Sandbox Code Playgroud)
服务合同的片段:
[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);
}
Run Code Online (Sandbox Code Playgroud)
我为我的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>
Run Code Online (Sandbox Code Playgroud)
所以,我的合同和服务绑定可能不匹配,如果相信这个消息,但从我对WCF的理解我的配置(或至少其背后的意图)是正确的.
有没有人对我的配置有什么问题?
我唯一能想到的就是因为你没有在很多细节中指定一个绑定,并且它使用HTTP(根据这个:"收听' http://mycomputer/MyWs.svc '")然后它是否使用默认(即basicHttpBinding),这是创建不匹配?
| 归档时间: |
|
| 查看次数: |
52211 次 |
| 最近记录: |