一,设置AXIS2_HOME环境
set AXIS2_HOME=F:\axis2-1.4.1-bin\axis2-1.5.1
注意,如果调试不通过,请多试几个版本.最好不要用axis1 因为他不支持BPEL协议
版本分析:axis2-1.5.1 =JDK1.5 axis2.1.4.1=JDK1.4(个人经验,不代表官方意见:}
二,生成代码:
%AXIS2_HOME%\bin\wsdl2java -uri http://localhost:808/HS_Service/Upload.asmx?wsdl -p client -s -o stub
生成文件放在C:\Documents and Settings\机器名下>
三,编写客户端代码
package client;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.rpc.ServiceException;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class ClientTask {
/** *//**
* @param args
* @throws RemoteException
* @throws ServiceException
* @throws MalformedURLException
*/
public static void main(String[] args) throws RemoteException, ServiceException, MalformedURLException {
// TODO Auto-generated method stub
Calendar calendar = new GregorianCalendar();
Date trialTime = new Date();
calendar.setTime(trialTime);
//fly --add
ClientTask ct = new ClientTask();
UploadStub us = new UploadStub();
UploadStub.JX jx = new UploadStub.JX();
System.out.println("校验用户开始.");
ct.getLogin("test_admin","1");
UploadStub.UploadProject uproject = new UploadStub.UploadProject();
jx.setJX010000028("283333");
jx.setJX010000001("上报状态");
jx.setJX010000004(4);
jx.setJX010000005(5);
jx.setJX030305001("1");
jx.setJX010000020(new BigDecimal("20.0"));
jx.setJX010000031(1);
jx.setJX010000032(3);
jx.setJX010000035("5");
jx.setJX010000019(new BigDecimal(1));
jx.setJX010000014(calendar.getInstance());//原为calendar
jx.setJX010000017(calendar.getInstance());
jx.setJX030308008(calendar.getInstance());
jx.setJX010000033(new BigDecimal(1));
jx.setJX010000034(new BigDecimal(1));
jx.setJX030302005(calendar.getInstance());
jx.setJX030303013(calendar.getInstance());
jx.setJX030304007(calendar.getInstance());
jx.setJX030306004(calendar.getInstance());
System.out.println(calendar.getInstance());
uproject.setJx(jx);
us.uploadProject(uproject);
System.out.println("上报状态:"+us.uploadProject(uproject).getUploadProjectResult());
}
public boolean getLogin(String username,String password) throws RemoteException {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setManageSession(true);
UploadStub stub = new UploadStub();
UploadStub.Login lg = new UploadStub.Login();
lg.setPUserName(username);
lg.setPPassword(password);
stub.login(lg);
System.out.println(stub.login(lg).getLoginResult());
return stub.login(lg).getLoginResult();
}
}
服务端保持状态:
MessageContext mc = MessageContext.getCurrentMessageContext();
ServiceContext sc = mc.getServiceContext();
客户端保持状态
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setManageSession(true);