在最近的m2m项目中,其中的web services 采用axis2 来实现,移动m2m提供wsdl文件,服务端代码用命令生成:
wsdl2java -uri SIInterface.wsdl -o . -p com.m2m.webservice.appori -d xmlbeans -s -ss -sd -ssi
这样会为服务端实现代码生成接口类,只要在其类(一般以*Skeleton.java 命名的类)中添加逻辑代码即可,举例如下:
ADCSIInterfaceResponseDocument doc = ADCSIInterfaceResponseDocument.Factory
.newInstance();
AdcSiRequest req = aDCSIInterface.getADCSIInterface().getRequest();
System.out.println("getVersion=" + req.getVersion());
处理请求的参数。。。
AdcSiResponse response = doc.addNewADCSIInterfaceResponse()
.addNewADCSIInterfaceResult();
response.setActionCode(2);
。。。。
doc.getADCSIInterfaceResponse().setADCSIInterfaceResult(response);
客户端调用举例:
ADCInterfaceForSIStub stub = new ADCInterfaceForSIStub();
ADCInterfaceForSIStub.AdcSiInterface adcSiInterface3;
ADCInterfaceForSIStub.AdcSiRequest request = new ADCInterfaceForSIStub.AdcSiRequest();
ADCInterfaceForSIStub.CustomHeaderE customHeader4;
adcSiInterface3 = (ADCInterfaceForSIStub.AdcSiInterface) getTestObject(ADCInterfaceForSIStub.AdcSiInterface.class);
customHeader4 = (ADCInterfaceForSIStub.CustomHeaderE) getTestObject(ADCInterfaceForSIStub.CustomHeaderE.class);
customHeader4.setCustomHeader(new ADCInterfaceForSIStub.CustomHeader());
request.setBizCode(Config.BizCode_Authen);
request.setTransID(TransIdGenerator.getTransIdNext());
request.setActionCode(1);
。。。。
adcSiInterface3.setRequest(request);
ADCInterfaceForSIStub.AdcSiInterfaceResponse adcSiInterfaceResp = stub
.AdcSiInterface(adcSiInterface3, customHeader4);
ADCInterfaceForSIStub.AdcSiResponse response = adcSiInterfaceResp
.getAdcSiInterfaceResult();
log.info("ResultCode:"+response.getResultCode());
log.info("ResultMsg:"+response.getResultMsg());
log.info("SvcCont:"+response.getSvcCont());
本文介绍了一个M2M项目中使用Axis2实现WebServices的过程。具体包括服务端通过wsdl2java生成接口类的方法及示例代码,以及客户端如何调用这些WebService接口。
612

被折叠的 条评论
为什么被折叠?



