用Axis2的客户端自动生成功能,生成了一个客户端。
具体操作如下(Window XP):
1、下载解压缩axis2.15。前提是已经安装好了jdk并设置好了JAVA_HOME系统变量。
2、将axis2.15的根路径添加 AXIS2_HOME系统变量,同时把axis2.15\bin目录放在path中。重启机器。
3、执行生成(先cd到axis2.15目录)
a. 到提供web service的网址下在wsdl,我使用的例子是,另存为EsmsService.wsdl到axis2.15根目录。
然后在工程目录下,运行以下DOS命令
> WSDL2Java -uri EsmsService.wsdl -p src -d xmlbeans -s -o src
生成源文件在src下。
b. 根据URL直接生成
> WSDL2java -uri -o src
4、在刚才声称目录的文件夹中建立Eclipse工程,将src文件拷贝进去。
5、编写客户端测试类:
public static void main(String[] args)...{
EsmsServiceServiceStub service = new EsmsServiceServiceStub(wsdlUrl);
GetMOMessage getMOMessage12 = new GetMOMessage();
org.apache.axis2.databinding.types.soapencoding.String s0 = new org.apache.axis2.databinding.types.soapencoding.String();
s0.setString(userName);
org.apache.axis2.databinding.types.soapencoding.String s1 = new org.apache.axis2.databinding.types.soapencoding.String();
s1.setString(password);
getMOMessage12.setIn0(s0);
getMOMessage12.setIn1(s1);
GetMOMessageResponse res = service.getMOMessage(getMOMessage12);
String resultStr = res.getGetMOMessageReturn().getString();
}
资料:
axis2 客户端调用三种方法
方法一:
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(
"");
options.setTo(targetEPR);
QName opAddEntry = new QName("", "addEntry");
Object[] opAddEntryArgs = new Object[] { entry };
serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);
方法二:
public static OMElement getEchoOMElement() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace(
"", "example1");
OMElement method = fac.createOMElement("echo", omNs);
OMElement value = fac.createOMElement("Text", omNs);
value.addChild(fac.createOMText(value, "Axis2 Echo String "));
method.addChild(value);
return method;
}
public static void main(String[] args) {
try {
OMElement payload = ClientUtil.getEchoOMElement();
Options options = new Options();
options.setTo(targetEPR);
options.setAction("urn:echo");
//Blocking invocation
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMElement result = sender.sendReceive(payload);
System.out.println(result);
System.out.println(options.getTo());
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
}
方法三:
利用插件生成客户端
private static String URL="";
public static void main(String[] args) throws RemoteException {
try {
WeatherServiceStub stub;
if (args != null && args.length != 0) {
stub = new WeatherServiceStub(args[0]);
} else {
stub = new WeatherServiceStub(URL);
}
WeatherServiceStub.SetWeather setWether = new WeatherServiceStub.SetWeather();
WeatherServiceStub.Weather wether = new WeatherServiceStub.Weather();
wether.setForecast("east");
wether.setRain(true);
wether.setTemperature(12.3f);
wether.setForecast("big");
setWether.setWeather(wether);
stub.setWeather(setWether);
WeatherServiceStub.GetWeatherResponse gw = new WeatherServiceStub.GetWeatherResponse();
System.out.println(gw.get_return());
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
相关资料:
阅读(1611) | 评论(0) | 转发(0) |