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

时间:2009-01-20 21:28:16

标签: java wcf

我目前正在开发一个需要使用Java Web服务的项目。如果我使用旧的webservices(asmx)连接到服务,它工作正常。但是,如果我尝试使用WCF客户端执行相同操作,则会出现以下错误:

内容类型text / xml;响应消息的charset = utf-8与绑定的内容类型不匹配(application / soap + xml; charset = 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>

作为旁注,我正在尝试使用soap 1.2,因为我需要能够从服务中捕获异常。

2 个答案:

答案 0 :(得分:2)

根据您的错误消息,它只是意味着您的服务器响应消息是SOAP 1.1,而您期望SOAP 1.2。

你必须在客户端上更改为SOAP 1.1(使用BasicHttpBinding,至少要测试它是否有效)。

答案 1 :(得分:1)

虽然SOAP 1.2规范不是 required ,但建议(即应该)SOAP消息使用内容类型的application / soap + xml

您应该在服务器端更改此设置。如果没有,那么我认为你将不得不摆弄配置文件中的textMessageEncoding绑定元素,使其接受text / xml内容类型。