1. server
1) 修改HelloService.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cn.com.demo.axis/HelloService" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd1="http://cn.com.demo.axis/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://cn.com.demo.axis/HelloService" name="HelloServiceService">
<types>
<schema targetNamespace="http://cn.com.demo.axis/xsd" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" elementFormDefault="qualified">
<complexType name="SOAPUser">
<all>
<element name="userId" type="xsd:int"/>
<element name="userName" type="xsd:string"/>
<element name="userPassword" type="xsd:string"/>
</all>
</complexType>
<!-- string -->
<element name="echoStringParam" type="xsd:string"/>
<element name="echoStringReturn" type="xsd:string"/>
<!-- object: tbuser -->
<element name="echoUserParam" type="xsd1:SOAPUser"/>
<element name="echoUserReturn" type="xsd1:SOAPUser"/>
</schema>
</types>
<message name="echoString">
<part name="stringParam" element="xsd1:echoStringParam"/>
</message>
<message name="echoStringResponse">
<part name="result" element="xsd1:echoStringReturn"/>
</message>
<message name="echoUser">
<part name="a" element="xsd1:echoUserParam"/>
</message>
<!-- object: tbuser -->
<message name="echoUserResponse">
<part name="result" element="xsd1:echoUserReturn"/>
</message>
<portType name="HelloServicePortType">
<operation name="echoString">
<input name="echoString" message="tns:echoString"/>
<output name="echoStringResponse" message="tns:echoStringResponse"/>
</operation>
<!-- object: tbuser -->
<operation name="echoUser">
<input name="echoUser" message="tns:echoUser"/>
<output name="echoUserResponse" message="tns:echoUserResponse"/>
</operation>
</portType>
<binding name="HelloServicePortBinding" type="tns:HelloServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="echoString">
<soap:operation soapAction="echoString" style="document"/>
<input>
<soap:body use="literal" namespace="http://cn.com.demo.axis/HelloService"/>
</input>
<output>
<soap:body use="literal" namespace="http://cn.com.demo.axis/HelloService"/>
</output>
</operation>
<operation name="echoUser">
<soap:operation soapAction="echoUser" style="document"/>
<input>
<soap:body use="literal" namespace="http://cn.com.demo.axis/HelloService"/>
</input>
<output>
<soap:body use="literal" namespace="http://cn.com.demo.axis/HelloService"/>
</output>
</operation>
</binding>
<service name="HelloServiceService">
<port name="HelloServicePort" binding="tns:HelloServicePortBinding">
<soap:address location="http://cn.com.demo.axis/stkv3/wsdl/HelloService.wsdl"/>
</port>
</service>
</definitions>
** 粗体部分为增加
路径: D:/axis151/mysamples/src/保留原来写的cn.com.demo.axis.HelloServiceServiceSkelton.java, Client.java, 其他文件删除。
D:/axis151/mysamples/wsdl2java -uri HelloService.wsdl -ss -sd -d xmlbeans -o . -p cn.com.demo.axis
生成新的服务端的代码
修改 cn.com.demo.axis.HelloServiceServiceSkelton.java
/**
* HelloServiceServiceSkeleton.java
*
* This file was auto-generated from WSDL
* by the Apache Axis2 version: 1.5.1 Built on : Oct 19, 2009 (10:59:00 EDT)
*/
package cn.com.demo.axis;
/**
* HelloServiceServiceSkeleton java skeleton for the axisService
*/
import axis.demo.com.cn.xsd.*;
public class HelloServiceServiceSkeleton{
/**
* Auto generated method signature
*
* @param echoStringParam
*/
public axis.demo.com.cn.xsd.EchoStringReturnDocument echoString
(
axis.demo.com.cn.xsd.EchoStringParamDocument echoStringParam
)
{
//TODO : fill this with the necessary business logic
EchoStringReturnDocument doc = EchoStringReturnDocument.Factory.newInstance();
doc.setEchoStringReturn(echoStringParam.getEchoStringParam());
return doc;
//throw new java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#echoString");
}
public axis.demo.com.cn.xsd.EchoUserReturnDocument echoUser
(
axis.demo.com.cn.xsd.EchoUserParamDocument echoStringParam
)
{
//TODO : fill this with the necessary business logic
EchoUserReturnDocument doc = EchoUserReturnDocument.Factory.newInstance();
doc.setEchoUserReturn(echoStringParam.getEchoUserParam());
return doc;
//throw new java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#echoString");
}
}
** 粗体为添加部分
2. client
D:/axis151/mysamples/wsdl2java -uri HelloService.wsdl -d xmlbeans -o . -p cn.com.demo.axis
生成新的客户端的代码
修改 Client.java, 在main里,增加
String url = "http://localhost/axis2/services/HelloServiceService";
try{
HelloServiceServiceStub stub = new HelloServiceServiceStub(null,url);
EchoUserParamDocument uRequest = EchoUserParamDocument.Factory.newInstance();
SOAPUser user = SOAPUser.Factory.newInstance();
user.setUserName("fj");
user.setUserPassword("fj");
uRequest.setEchoUserParam(user);
EchoUserReturnDocument doc = stub.echoUser(uRequest);
SOAPUser retUser = uRequest.getEchoUserParam();
System.out.println(retUser.getUserName());
System.out.println(retUser.getUserPassword());
}catch(Exception ex){
ex.printStackTrace();
}
3. build
路径:
D:/axis151/mysamples/ant clean
D:/axis151/mysamples/ant jar.all
生成的服务端.aar文件放置到%tomcat_home%/webapp/axis2/web-inf/services下。
5. test
D:/axis151/mysamples/ant run.client