根据wsdl生成客户端:Use of SOAP Encoding is not supported

一.生成方式选择

接收到服务端第三方给的wsdl文件,需要在本地生成客户端调用。调用或生成客户端的方式有很多种,可能你会使用eclipse上的插件、IDEA上的插件、使用xfire简单的调用方式等,会碰到各种问题,就是生成不了。其实选择哪种方式,要根据wsdl定义stype和use的方式。

stype描述了服务调用方式:rpc或document,use定义了类型:encoded或literal

二.wsdl文件的片段
<wsdl:message name="sigResponse">
<wsdl:part name="sigReturn" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="sigRequest">
<wsdl:part name="province" type="soapenc:string"/>
<wsdl:part name="caller" type="soapenc:string"/>
<wsdl:part name="called" type="soapenc:string"/>
<wsdl:part name="sigType" type="soapenc:string"/>
<wsdl:part name="sigTime" type="soapenc:string"/>
</wsdl:message>
<wsdl:portType name="SigMessageDellImpl">
<wsdl:operation name="SigMsg" parameterSigMsg="province caller called sigType sigTime">
<wsdl:input message="impl:sigRequest" name="sigRequest"/>
<wsdl:output message="impl:sigResponse" name="sigResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="sigMessageServicesSoapBinding" type="impl:SigMessageDellImpl">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="SigMsg">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="sigRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://impl.service.client.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="sigResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://*.*.*.*:*/SMSWebService/services/sigMessageServices" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SigMessageDellImplService">
<wsdl:port binding="impl:sigMessageServicesSoapBinding" name="sigMessageServices">
<wsdlsoap:address location="http://*.*.*.*:*/SMSWebService/services/sigMessageServices"/>
</wsdl:port>
</wsdl:service>
三.碰到的问题

1.我建议调用不是自己生成的服务端的wsdl,最好使用wsimport方式,调用后报错:Use of SOAP Encoding is not supported

xiaoxiangdeMacBook-Pro:~ Simons$ wsimport -keep -p zhenzhen -d ~ http://*.*.*.*/SMSWebService/services/sigMessageServices/?wsdl
parsing WSDL...


[ERROR] "Use of SOAP Encoding is not supported. 
SOAP extension element on line 48 in http://*.*.*.*/SMSWebService/services/sigMessageServices/?wsdl has use="encoded" "


    Failed to parse the WSDL.

原因:这和JDK版本有关,进入到jdk的bin目录下,查看JAX-WS的版本,而Version 2 of JAX-WS does not support rpc/encoded anymore,就是wsdl生成时选择了rpc/encoded方式(仔细查看wsdl可以看到style=”rpc”,use=”encoded”),JDK1.7中的JAX-WS已经不支持了。

xiaoxiangdeMacBook-Pro:bin Simons$ wsimport -version
JAX-WS RI 2.2.4-b01
四.解决方案

1.使用Apache Axis1.0中的WSDL2Java来生成

java org.apache.axis.wsdl.WSDL2Java http://someurl?WSDL

另外调用WSDL2Java需要相关jars,使用-cp添加进来,不支持使用通配符。提醒:linux下jar之间使用冒号隔开:,windows下jar之间使用分号隔开

java -cp mail-1.4.jar;saaj-api-1.3.jar;jaxrpc-1.1.jar;commons-discovery-0.2.jar;commons-logging-1.1.jar;axis-1.4.jar;activation-1.1.jar;wsdl4j-1.4.jar org.apache.axis.wsdl.WSDL2Java http://*.*.*.*/SMSWebService/services/sigMessageServices?wsdl

jar包可以在maven repository去下载,分别是:

mail-1.4.jar;
saaj-api-1.3.jar;
jaxrpc-1.1.jar;
commons-discovery-0.2.jar;
commons-logging-1.1.jar;
axis-1.4.jar;
activation-1.1.jar;
wsdl4j-1.4.jar

生成文件:

SigMessageDellImpl.java
SigMessageDellImplService.java
SigMessageDellImplServiceLocator.java
SigMessageServicesSoapBindingStub.java

2.调用方式如下,不是直接new stub

public class TestClient {
    public static void main(String[] args) throws Exception{
        SigMessageDellImplService locator=new SigMessageDellImplServiceLocator();
        SigMessageServicesSoapBindingStub stub=(SigMessageServicesSoapBindingStub)locator.getsigMessageServices();
        String result=stub.sigMsg("310000","02163630000","18000000000","8","2016-08-03 22:08:08");
        System.out.println("result:"+result);
    }
}

以上!

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值