繁体   English   中英

期望SOAP 1.1内容类型的WCF SOAP 1.2服务

[英]WCF SOAP 1.2 service expecting SOAP 1.1 content type

我正在构建一个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

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

我知道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>

从这个响应中,它告诉我我的请求是正确形成的 - 它是一个具有正确内容类型的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>

服务合同的片段:

[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>

所以,我的合同和服务绑定可能不匹配,如果相信这个消息,但从我对WCF的理解我的配置(或至少其背后的意图)是正确的。

有没有人对我的配置有什么问题?

我唯一能想到的就是因为你没有在很多细节中指定一个绑定,并且它使用HTTP(根据这个:“收听' http://mycomputer/MyWs.svc '”)然后它是否使用默认值(即basicHttpBinding )来创建不匹配?

当我的服务有多个绑定时,我遇到了同样的问题。 当我删除所有绑定并且只留下一个未命名的绑定时,错误消息消失了。

请检查此链接如何:配置WCF服务以与ASP.NET Web服务客户端进行互操作

若要将Windows Communication Foundation(WCF)服务端点配置为可与ASP.NET Web服务客户端进行互操作,请使用System.ServiceModel。 BasicHttpBinding类型作为服务端点的绑定类型。

此外,定义两个端点可以使用同一服务的HTTP和HTTPS版本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM