上面2章我们WebService已经可以正常发布了。现在我们来写服务器端和客户端代码:
我们用Aixs生成java code里有个SyncNotifySPSoapBindingImpl类,这个就是写服务器端代码入口,如果你用wsdl不一样那应该是***Impl.java 这样规则的文件。
?
贴出我的服务器端代码:
public class SyncNotifySPSoapBindingImpl implements com.unicom.vac.bossagent.soap.SyncNotifySPService{
??? public com.unicom.vac.bossagent.soap.sync.rsp.OrderRelationUpdateNotifyResponse orderRelationUpdateNotify(com.unicom.vac.bossagent.soap.sync.req.OrderRelationUpdateNotifyRequest orderRelationUpdateNotifyRequest) throws java.rmi.RemoteException {
?????System.out.println("已调用");
??? ?OrderRelationUpdateNotifyResponse response=new OrderRelationUpdateNotifyResponse();
??? ?response.setRecordSequenceId("1");
??? ?response.setResultCode(1);
??? ?return response;
??? }
?
}
贴出我客户端代码:
public class WebServiceClient {
?
?private SyncNotifySPServiceServiceLocator locator=null;
?private SyncNotifySPServiceService serviceService=null;
?private OrderRelationUpdateNotifyResponse response=null;
?public com.unicom.vac.bossagent.soap.sync.rsp.OrderRelationUpdateNotifyResponse setRequest(){
??try{
??OrderRelationUpdateNotifyRequest orunr=new OrderRelationUpdateNotifyRequest();
??locator=new SyncNotifySPServiceServiceLocator();
??locator.setEndpointAddress("SyncNotifySP","http://localhost:8080/VacSyncService/services/SyncNotifySP");
??serviceService=locator;
??SyncNotifySPService ser=serviceService.getSyncNotifySP();
??orunr.setContent("1");
??orunr.setEffectiveDate("2");
??orunr.setEncodeStr("3");
??orunr.setExpireDate("4");
??orunr.setLinkId("5");
??orunr.setProductId("6");
??orunr.setRecordSequenceId("7");
??orunr.setServiceType("8");
??orunr.setSpId("9");
??orunr.setTime_stamp("10");
??orunr.setUpdateTime("11");
??orunr.setUpdateDesc("12");
??orunr.setUpdateType(13);
??orunr.setUserId("14");
??orunr.setUserIdType(15);
??response=ser.orderRelationUpdateNotify(orunr);
??if(response!=null){
???System.out.println(response.getRecordSequenceId());
??}else{
???System.out.println("response is null!");
??}
??
}catch(Exception ex){
???ex.printStackTrace();
??}
??return response;
??
?}
?/**
? * @param args
? */
?public static void main(String[] args) {
??// TODO Auto-generated method stub
??WebServiceClient wc=new WebServiceClient();
??wc.setRequest();
?}
}
?
?
WebService的学习就先介绍到这里。我测试客户端代码调用服务器端代码没有问题。这个例子只做学习之用。