简体   繁体   中英

WCF client errors when consuming Java services

I'm currently working on a project where I need to consume a Java webservice. If I connect to the service using old webservices (asmx) it works fine. However, If I try to do the same thing with a WCF client I get the following error:

The content type text/xml; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.

My is very simple and it looks like the following:

//classic web service
OldSkoolService.HelloService serviceCall = new esb_wsdlsample.OldSkoolService.HelloService();
Console.WriteLine(serviceCall.SoapVersion);
Console.WriteLine(serviceCall.sayHello("something"));

HelloServiceClient prototypeClient = new HelloServiceClient();
var serviceChannel = prototypeClient.ChannelFactory;

Console.WriteLine(serviceChannel.Endpoint.Binding.MessageVersion);
Console.WriteLine(prototypeClient.sayHello("somethinge")); //<-- Error occurs here       

The the binding/endpoint config file is quite simple as well:

<bindings>
  <customBinding>
    <binding name="Soap12Binding">
      <textMessageEncoding messageVersion="Soap12"/>
      <httpTransport />              
    </binding>
  </customBinding>        
</bindings>
<client>
    <endpoint address="http://10.10.6.51:7001/esb/HelloService" behaviorConfiguration=""
        binding="customBinding" bindingConfiguration="Soap12Binding" contract="Prototype.ESB.HelloService"
        name="HelloServicePort" />          
</client>

As a side note I'm trying to use soap 1.2, because I need to be able to catch exceptions from the service.

Based on your error message, it simply means that your Server response message is SOAP 1.1, while you expect SOAP 1.2.

You'll have to change to SOAP 1.1 on the client (using BasicHttpBinding, at least do it to test and see if it works that way).

While it isn't required by the SOAP 1.2 specification, it is recommended (ie SHOULD ) that SOAP messages use a content-type of application/soap+xml.

You should change this on the server side. If not, then I think that you will have to fiddle around with the textMessageEncoding binding element in the config file to make it accept the text/xml content-type.

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