原生java调用webservice的方法,不用生成客户端代码
- <span style="font-family: Arial, Helvetica, sans-serif;">package com.kingdee.eas.cp.trd.webservice.taskinter;</span>
package com.kingdee.eas.cp.trd.webservice.taskinter;
- import java.rmi.RemoteException;
- import javax.xml.namespace.QName;
- import javax.xml.rpc.ServiceException;
- import org.apache.axis.client.Call;
- import org.apache.axis.client.Service;
- import org.apache.axis.message.SOAPHeaderElement;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.webservice.login.WSContext;
- public class TaskInterUtil
- {
- public static String getUserCreditFilesData(Context ctx,String userId)
- {
- try {
- Service s = new Service();
- Call call = (Call) s.createCall();
- call.setOperationName("login");
- call.setTargetEndpointAddress("http://10.0.55.5:6888/ormrpc/services/EASLogin?wsdl");
- call.setReturnType(new QName("urn:client", "WSContext"));
- call.setReturnClass(WSContext.class);
- call.setReturnQName(new QName("", "loginReturn"));
- call.setMaintainSession(true);
- String headerValue ;
- String headerNamePlace = "http://login.webservice.bos.kingdee.com";
- // WSContext result = ((WSContext) call.invoke(new Object[] { "sysWS","sysWS","eas","TESTSSC8", "l2",Integer.valueOf("2"),"BaseDB"}));
- WSContext result = ((WSContext) call.invoke(new Object[] { "sysWS","sysWS","eas","TESTSSC8", "l2",2}));
- String sessionid = result.getSessionId();
- System.out.println(sessionid);
- call.clearOperation();
- //call = (Call) new Service().createCall();,不能创建一个新的call
- call.setOperationName("getUserCreditFilesData");
- // call.setOperationName("createJob");
- call.setMaintainSession(true);
- call.setTargetEndpointAddress("http://10.0.55.5:6888/ormrpc/services/WSTaskInterFacede?wsdl");
- call.addHeader(new SOAPHeaderElement("http://login.webservice.bos.kingdee.com","SessionId", sessionid));
- // boolean b =(Boolean) call.invoke(new Object[] { "111"});
- Object b = call.invoke(new Object[] { "bLXZIU9+SiuLKkJor2m9NhO33n8=", "", "", "", "", "", "", "10.0.55.5"});
- System.out.println("ssss");
- } catch (ServiceException e) {
- e.printStackTrace();
- } catch (RemoteException e) {
- e.printStackTrace(); }
- return "";
- }
- }
import java.rmi.RemoteException;import javax.xml.namespace.QName;import javax.xml.rpc.ServiceException;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.message.SOAPHeaderElement;import com.kingdee.bos.Context;import com.kingdee.bos.webservice.login.WSContext;public class TaskInterUtil{ public static String getUserCreditFilesData(Context ctx,String userId) { try { Service s = new Service(); Call call = (Call) s.createCall(); call.setOperationName("login"); call.setTargetEndpointAddress("http://10.0.55.5:6888/ormrpc/services/EASLogin?wsdl"); call.setReturnType(new QName("urn:client", "WSContext")); call.setReturnClass(WSContext.class); call.setReturnQName(new QName("", "loginReturn")); call.setMaintainSession(true); String headerValue ; String headerNamePlace = "http://login.webservice.bos.kingdee.com"; // WSContext result = ((WSContext) call.invoke(new Object[] { "sysWS","sysWS","eas","TESTSSC8", "l2",Integer.valueOf("2"),"BaseDB"})); WSContext result = ((WSContext) call.invoke(new Object[] { "sysWS","sysWS","eas","TESTSSC8", "l2",2})); String sessionid = result.getSessionId(); System.out.println(sessionid); call.clearOperation(); //call = (Call) new Service().createCall();,不能创建一个新的call call.setOperationName("getUserCreditFilesData");// call.setOperationName("createJob"); call.setMaintainSession(true); call.setTargetEndpointAddress("http://10.0.55.5:6888/ormrpc/services/WSTaskInterFacede?wsdl"); call.addHeader(new SOAPHeaderElement("http://login.webservice.bos.kingdee.com","SessionId", sessionid));// boolean b =(Boolean) call.invoke(new Object[] { "111"}); Object b = call.invoke(new Object[] { "bLXZIU9+SiuLKkJor2m9NhO33n8=", "", "", "", "", "", "", "10.0.55.5"}); System.out.println("ssss"); } catch (ServiceException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } return ""; }}
2.
- String result = null;
- try {
- Properties p = new Properties();
- String propertiesUrl = "com/kingdee/eas/fi/gl/client/propertie.properties";
- InputStream ins = VoucherEditUICTEx.class.getClassLoader().getResourceAsStream(propertiesUrl);
- p.load(ins);
- String showImageUrl = p.getProperty("showImageUrl");
- //直接引用远程的wsdl文件
- //以下都是套路
- Service service = new Service();
- Call call = (Call) service.createCall();
- call.setTargetEndpointAddress(showImageUrl);
- call.setOperationName("imageOutSrv");//WSDL里面描述的接口名称
- call.addParameter("inJsonString", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN);//接口的参数
- call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
- // companyNumber = "CWGX001";
- // voucherPeriod = "2015-08";
- // voucherTitle = "记字集团";
- // voucherCode = "WK06-0001";
- String AppID = "EAS701";
- String Provider = "IMSSC";
- StringBuffer param = new StringBuffer();
- param.append(" { ");
- param.append(" \"Message\":{ ");
- param.append(" \"Header\":{ ");
- param.append(" \"AppID\":\""+AppID+"\", ");
- param.append(" \"Provider\":\""+Provider+"\" ");
- param.append(" }, ");
- param.append(" \"Body\":{ ");
- param.append(" \"ACTION_METHOD\":\"showImage\", ");
- param.append(" \"PARAMS\":{ ");
- param.append(" \"COMPANY_CODE\":\""+companyNumber+"\", ");
- param.append(" \"VOUCHER_PERIOD\":\""+voucherPeriod+"\", ");
- param.append(" \"VOUCHER_TITLE\":\""+voucherTitle+"\", ");
- param.append(" \"VOUCHER_CODE\":\""+voucherCode+"\" ");
- param.append(" } ");
- param.append(" } ");
- param.append(" } ");
- param.append(" } ");
- result = (String)call.invoke(new Object[]{param.toString()});
- //给方法传递参数,并且调用方法
- System.out.println("result is "+result);
- } catch (Exception e1) {
- e1.printStackTrace();
- MsgBox.showInfo("EAS核算凭证影像调阅接口调用失败");
- SysUtil.abort();
- }
String result = null; try { Properties p = new Properties(); String propertiesUrl = "com/kingdee/eas/fi/gl/client/propertie.properties"; InputStream ins = VoucherEditUICTEx.class.getClassLoader().getResourceAsStream(propertiesUrl); p.load(ins); String showImageUrl = p.getProperty("showImageUrl"); //直接引用远程的wsdl文件 //以下都是套路 Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(showImageUrl); call.setOperationName("imageOutSrv");//WSDL里面描述的接口名称 call.addParameter("inJsonString", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN);//接口的参数 call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型 // companyNumber = "CWGX001";// voucherPeriod = "2015-08";// voucherTitle = "记字集团";// voucherCode = "WK06-0001"; String AppID = "EAS701"; String Provider = "IMSSC"; StringBuffer param = new StringBuffer(); param.append(" { "); param.append(" \"Message\":{ "); param.append(" \"Header\":{ "); param.append(" \"AppID\":\""+AppID+"\", "); param.append(" \"Provider\":\""+Provider+"\" "); param.append(" }, "); param.append(" \"Body\":{ "); param.append(" \"ACTION_METHOD\":\"showImage\", "); param.append(" \"PARAMS\":{ "); param.append(" \"COMPANY_CODE\":\""+companyNumber+"\", "); param.append(" \"VOUCHER_PERIOD\":\""+voucherPeriod+"\", "); param.append(" \"VOUCHER_TITLE\":\""+voucherTitle+"\", "); param.append(" \"VOUCHER_CODE\":\""+voucherCode+"\" "); param.append(" } "); param.append(" } "); param.append(" } "); param.append(" } "); result = (String)call.invoke(new Object[]{param.toString()}); //给方法传递参数,并且调用方法 System.out.println("result is "+result); } catch (Exception e1) { e1.printStackTrace(); MsgBox.showInfo("EAS核算凭证影像调阅接口调用失败"); SysUtil.abort(); }