axis2 生成webservice客户端jar及使用

阅读更多

参考:

https://my.oschina.net/suyewanwan/blog/110662

 

axis2下载:http://axis.apache.org/axis2/java/core/download.html

我下载的这个:axis2-1.7.4-bin.zip

 

axis2构建webService客户端代码

ant把构建完成的代码打成jar包

 

1、wsdl2java命令生成客户端源文件

 

D:\axis2-1.7.2\bin>wsdl2java.bat -uri http://192.168.0.0/SMSend/Service.asmx?wsdl -o F:\tt -p com.bd.zd

wsdl2java -uri http://192.168.0.0/SMSend/Service.asmx?wsdl -o F:\tt -p com.bd.zd

 

-uri : wsdl文件的位置,注意检查文件路径之间不要有空格哦~有空格就需要把这段路径加“”(引号)。

-o:文件的输出位置。默认情况两个文件( java文件及build.xml)都在axis2-1.5\bin目录下

-p:生成的java文件的包名

 

2、ant打jar包

 

D:\axis2-1.7.2\bin>cd /d F:\tt
F:\tt>ant jar.client
xxxxxx....
jar.client:
      [jar] Building jar: F:\tt\build\lib\Service-test-client.jar

BUILD SUCCESSFUL

jar 在build\lib下

 

 

3、jar客户端调用:

 

    def axis(){

        ServiceStub stub = new ServiceStub();  //这个是生成的类,可能你的类名和我的是不一样的
        stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
        //加入头部验证
        ServiceStub.MySoapHeaderE headerE=new ServiceStub.MySoapHeaderE();//这里的生成的类可能和你的也不同
        ServiceStub.MySoapHeader header=new ServiceStub.MySoapHeader();//这个header即是web service的header头
        //这里执行一些属性赋值操作,一般包括用户名和密码之类
        header.name="xxxxx"
        header.passWord="xxxxxxxxxxxxxxxxxxxx"
        headerE.setMySoapHeader(header); //需要将该头加进去

        ServiceStub.Insert insert = new ServiceStub.Insert();
        insert.userID = "test100"
        insert.userName="qq"
        insert.orgID="123"
        insert.orgName="组织机构名称"
        insert.messageInfo="测试"
        insert.reNum="15352720000"
        stub.insert(insert,headerE)

    }

 

 

备注需要的jar包:

在axis2中都有,可在axis2\lib 中获取!!!

 

参考:http://www.cnblogs.com/winclpt/articles/5206510.html

 

axis2 webservice 服务端jar包:

-->axis2-kernel-1.6.1.jar
-->axis2-spring-1.6.1.jar
-->axis2-transport-http-1.6.1.jar
-->XmlSchema-1.4.7.jar
-->wsdl4j-1.6.2.jar
-->axiom-api-1.2.12.jar
-->axiom-impl-1.2.12.jar
-->neethi-3.0.1.jar
-->axis2-transport-local-1.6.1.jar
-->commons-httpclient-3.1.jar
-->axis2-jaxws-1.6.1.jar
-->spring.jar
-->commons-logging-1.1.1.jar
-->axis2-adb-1.7.0.jar

 

axis2 webservice client端jar包 :

-->axis2-kernel-1.6.1.jar
-->axis2-adb-1.6.1.jar
-->axiom-api-1.2.12.jar
-->commons-logging-1.1.1.jar
-->wsdl4j-1.6.2.jar
-->XmlSchema-1.4.7.jar
-->axiom-impl-1.2.12.jar
-->neethi-3.0.1.jar
-->axis2-transport-local-1.6.1.jar
-->axis2-transport-http-1.6.1.jar
-->commons-httpclient-3.1.jar
-->httpcore-4.0.jar
-->commons-codec-1.3.jar

 

各种类缺失对应的jar包:

java.lang.NoClassDefFoundError: org/apache/woden/WSDLException		--->woden-core-1.0M10.jar
org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder   -->axis2-spring-1.6.1.jar
org.apache.axis2.transport.http.AxisServlet				-->axis2-transport-http-1.6.1.jar
javax.wsdl.xml.WSDLLocator                                              -->wsdl4j-1.6.2.jar
org.apache.ws.commons.schema.resolver.URIResolver                       -->XmlSchema-1.4.7.jar
org.apache.axiom.om.OMNode                                              -->axiom-api-1.2.12.jar
org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory           -->axiom-impl-1.2.12.jar
org.apache.neethi.PolicyComponent                                       -->neethi-3.0.1.jar
org.apache.axis2.transport.local.LocalTransportSender                   -->axis2-transport-local-1.6.1.jar
org.apache.commons.httpclient.HttpException                             -->commons-httpclient-3.1.jar
javax.mail.internet.ParseException                                      -->mail-1.4.jar
org.apache.commons.fileupload.FileItemFactory                           -->commons-fileupload-1.2.jar
org.apache.woden.resolver.URIResolver                                   -->woden-api-1.0M9.jar
org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher            -->axis2-jaxws-1.6.1.jar
org.apache.commons.io.FileUtils                                         -->commons-io-1.4.jar
org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver                 -->axis2-adb-1.6.1.jar
org.apache.axis2.rpc.client.RPCServiceClient                            -->axis2-adb-1.6.1.jar
org.apache.axis2.AxisFault						-->axis2-kernel-1.6.1.jar
org.apache.axis2.addressing.EndpointReference                           -->axis2-kernel-1.6.1.jar
org.apache.axis2.client.Options                                         -->axis2-kernel-1.6.1.jar
org.apache.commons.logging.LogFactory                                   -->commons-logging-1.1.1.jar
org.apache.axis2.transport.http.CommonsHTTPTransportSender              -->axis2-transport-http-1.6.1.jar
org.apache.http.HttpResponseFactory                                     -->httpcore-4.0.jar
org.apache.commons.codec.DecoderException                               -->commons-codec-1.3.jar

 

 

 

 

 

 

 

你可能感兴趣的:(axis2,webService)