简体   繁体   English

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

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

I'm building a WCF web service that requires interop with non-WCF clients (in fact, there will be no WCF clients). 我正在构建一个WCF Web服务,需要与非WCF客户端互操作(实际上,没有WCF客户端)。

I've already written a WSDL using SOAP 1.2 ( as per this example ). 我已经使用SOAP 1.2编写了一个WSDL( 根据这个例子 )。 I've validated the WSDL and have used this file (not the WSDL generated by WCF, which is superficially different) to create a soapUI test project. 我已经验证了WSDL并且已经使用了这个文件(不是由WCF生成的WSDL,这在表面上是不同的)来创建一个soapUI测试项目。

I have a requirement that the web service will support SOAP 1.2, so I can't just fall back to SOAP 1.1 (which worked just fine in an early prototype). 我要求Web服务支持SOAP 1.2,所以我不能回到SOAP 1.1(它在早期的原型中运行得很好)。

I've used WSCF.blue to generate my WCF service, interface, and data contract classes. 我已经使用WSCF.blue生成我的WCF服务,接口和数据协定类。 Everything compiles nicely and the endpoint is exposed if I hit the WCF service in my browser. 如果我在浏览器中点击WCF服务,一切都很好地编译并暴露端点。 All seems well with the world. 一切似乎与世界很好。

When I try to call a method from soapUi I get the following response from the server (as visible from soapUI): 当我尝试从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

(Actual method names and namespaces have been manually changed for the purposes of this question. Any typos in namespace are not errors in my code - just an oversight in typing up this question) (出于此问题的目的,已经手动更改了实际的方法名称和命名空间。命名空间中的任何拼写错误都不是我的代码中的错误 - 只是在输入此问题时的疏忽)

I know that SOAP 1.1 specifies that the content type must be text/xml . 我知道SOAP 1.1指定内容类型必须是text / xml SOAP 1.2 requires application/soap+xml . SOAP 1.2需要application / soap + xml

My raw request (as per soapUI): 我的原始请求(根据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>

From this response, it tells me that my request is properly formed - it's a SOAP 1.2 request with the correct content type. 从这个响应中,它告诉我我的请求是正确形成的 - 它是一个具有正确内容类型的SOAP 1.2请求。 My WCF service, however, does not expect this content type, which I assume means I have not configured it correctly and it still thinks it's a SOAP 1.1 web service. 但是,我的WCF服务不期望这种内容类型,我认为这意味着我没有正确配置它,它仍然认为它是一个SOAP 1.1 Web服务。

Minimal Web.config, as per this blog post : 最小的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>

A snippet of the service 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);
}

I enabled service tracing for my WCF service and see the following exception that seems to confirm my hypothesis: 我为我的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>

So, my contract and service bindings are probably mismatched, if this message is to believed, but from what I understand of WCF my configuration (or at least the intent behind it) is correct. 所以,我的合同和服务绑定可能不匹配,如果相信这个消息,但从我对WCF的理解我的配置(或至少其背后的意图)是正确的。

Does anyone have any ideas as to what's wrong with my configuration? 有没有人对我的配置有什么问题?

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

I had the same issue when I had multiple bindings on my service. 当我的服务有多个绑定时,我遇到了同样的问题。 When I removed all bindings and only left one unnamed binding in place, the error message disappeared. 当我删除所有绑定并且只留下一个未命名的绑定时,错误消息消失了。

Please check this link How to: Configure WCF Service to Interoperate with ASP.NET Web Service Clients . 请检查此链接如何:配置WCF服务以与ASP.NET Web服务客户端进行互操作

To configure a Windows Communication Foundation (WCF) service endpoint to be interoperable with ASP.NET Web service clients, use the System.ServiceModel. 若要将Windows Communication Foundation(WCF)服务端点配置为可与ASP.NET Web服务客户端进行互操作,请使用System.ServiceModel。 BasicHttpBinding type as the binding type for your service endpoint. BasicHttpBinding类型作为服务端点的绑定类型。

Also, defining two endpoints you can use HTTP and HTTPS versions of the same service 此外,定义两个端点可以使用同一服务的HTTP和HTTPS版本

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

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