代码之家  ›  专栏  ›  技术社区  ›  Korbin

使用Java服务时出现WCF客户端错误

  •  4
  • Korbin  · 技术社区  · 16 年前

    内容类型为text/xml;响应消息的charset=utf-8与绑定的内容类型不匹配(应用程序/soap+xml;字符集=utf-8)。如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。

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

    绑定/端点配置文件也非常简单:

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

    2 回复  |  直到 16 年前
        1
  •  2
  •   Philippe    16 年前

    根据您的错误消息,这仅仅意味着您的服务器响应消息是SOAP1.1,而您期望的是SOAP1.2。

    您必须在客户机上更改为SOAP1.1(使用BasicHttpBinding,至少要进行测试,看看是否可以这样工作)。

        2
  •  1
  •   casperOne    16 年前

    而事实并非如此 根据SOAP 1.2规范,建议(即。 )SOAP消息使用的内容类型为application/SOAP+xml。

    您应该在服务器端对此进行更改。如果没有,那么我认为您必须在配置文件中处理textMessageEncoding绑定元素,使其接受text/xml内容类型。