简体   繁体   中英

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).

I've already written a WSDL using SOAP 1.2 ( as per this example ). 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.

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).

I've used WSCF.blue to generate my WCF service, interface, and data contract classes. Everything compiles nicely and the endpoint is exposed if I hit the WCF service in my browser. 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):

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.2 requires application/soap+xml .

My raw request (as per 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. 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.

Minimal Web.config, as per 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>

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:

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.

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 .

To configure a Windows Communication Foundation (WCF) service endpoint to be interoperable with ASP.NET Web service clients, use the System.ServiceModel. BasicHttpBinding type as the binding type for your service endpoint.

Also, defining two endpoints you can use HTTP and HTTPS versions of the same service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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