博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
原生java调用webservice的方法,不用生成客户端代码
阅读量:5877 次
发布时间:2019-06-19

本文共 7989 字,大约阅读时间需要 26 分钟。

原生java调用webservice的方法,不用生成客户端代码
[java]
  1. <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;
[java]
  1. import java.rmi.RemoteException;  
  2.   
  3. import javax.xml.namespace.QName;  
  4. import javax.xml.rpc.ServiceException;  
  5.   
  6. import org.apache.axis.client.Call;  
  7. import org.apache.axis.client.Service;  
  8. import org.apache.axis.message.SOAPHeaderElement;  
  9.   
  10. import com.kingdee.bos.Context;  
  11. import com.kingdee.bos.webservice.login.WSContext;  
  12.   
  13. public class TaskInterUtil  
  14. {  
  15.     public static String getUserCreditFilesData(Context ctx,String userId)  
  16.     {  
  17.         try {  
  18.             Service s = new Service();  
  19.             Call call = (Call) s.createCall();  
  20.             call.setOperationName("login");  
  21.             call.setTargetEndpointAddress("http://10.0.55.5:6888/ormrpc/services/EASLogin?wsdl");  
  22.             call.setReturnType(new QName("urn:client", "WSContext"));  
  23.             call.setReturnClass(WSContext.class);  
  24.             call.setReturnQName(new QName("", "loginReturn"));  
  25.             call.setMaintainSession(true);  
  26.             String headerValue ;  
  27.             String headerNamePlace = "http://login.webservice.bos.kingdee.com";  
  28.             //                  WSContext result = ((WSContext) call.invoke(new Object[] { "sysWS","sysWS","eas","TESTSSC8", "l2",Integer.valueOf("2"),"BaseDB"}));  
  29.             WSContext result = ((WSContext) call.invoke(new Object[] { "sysWS","sysWS","eas","TESTSSC8", "l2",2}));  
  30.             String sessionid = result.getSessionId();  
  31.             System.out.println(sessionid);  
  32.             call.clearOperation();  
  33.   
  34.             //call = (Call)  new Service().createCall();,不能创建一个新的call  
  35.   
  36.             call.setOperationName("getUserCreditFilesData");  
  37. //          call.setOperationName("createJob");  
  38.             call.setMaintainSession(true);  
  39.             call.setTargetEndpointAddress("http://10.0.55.5:6888/ormrpc/services/WSTaskInterFacede?wsdl");  
  40.             call.addHeader(new SOAPHeaderElement("http://login.webservice.bos.kingdee.com","SessionId", sessionid));  
  41. //          boolean b =(Boolean) call.invoke(new Object[] { "111"});   
  42.             Object b = call.invoke(new Object[] { "bLXZIU9+SiuLKkJor2m9NhO33n8=", "", "", "", "", "", "", "10.0.55.5"});   
  43.             System.out.println("ssss");  
  44.         } catch (ServiceException e) {       
  45.             e.printStackTrace();        
  46.         } catch (RemoteException e) {   
  47.             e.printStackTrace();    }  
  48.           
  49.   
  50.           
  51.         return "";  
  52.     }  
  53. }  
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.

 

[java]
  1.         String result = null;  
  2.         try {    
  3.             Properties p = new Properties();  
  4.             String propertiesUrl = "com/kingdee/eas/fi/gl/client/propertie.properties";  
  5.             InputStream ins = VoucherEditUICTEx.class.getClassLoader().getResourceAsStream(propertiesUrl);  
  6.             p.load(ins);  
  7.   
  8.             String showImageUrl = p.getProperty("showImageUrl");  
  9.             //直接引用远程的wsdl文件    
  10.             //以下都是套路     
  11.             Service service = new Service();    
  12.             Call call = (Call) service.createCall();    
  13.             call.setTargetEndpointAddress(showImageUrl);    
  14.             call.setOperationName("imageOutSrv");//WSDL里面描述的接口名称    
  15.             call.addParameter("inJsonString", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN);//接口的参数    
  16.             call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型      
  17.               
  18. //          companyNumber = "CWGX001";  
  19. //          voucherPeriod = "2015-08";  
  20. //          voucherTitle = "记字集团";  
  21. //          voucherCode = "WK06-0001";  
  22.               
  23.             String AppID = "EAS701";  
  24.             String Provider = "IMSSC";  
  25.               
  26.             StringBuffer param = new StringBuffer();  
  27.             param.append("  {                   ");  
  28.             param.append("      \"Message\":{                   ");  
  29.             param.append("          \"Header\":{                    ");  
  30.             param.append("              \"AppID\":\""+AppID+"\",                    ");  
  31.             param.append("              \"Provider\":\""+Provider+"\"                   ");  
  32.             param.append("          },                  ");  
  33.             param.append("          \"Body\":{                  ");  
  34.             param.append("              \"ACTION_METHOD\":\"showImage\",                    ");  
  35.             param.append("              \"PARAMS\":{                    ");  
  36.             param.append("                  \"COMPANY_CODE\":\""+companyNumber+"\",                 ");  
  37.             param.append("                  \"VOUCHER_PERIOD\":\""+voucherPeriod+"\",                   ");  
  38.             param.append("                  \"VOUCHER_TITLE\":\""+voucherTitle+"\",                 ");  
  39.             param.append("                  \"VOUCHER_CODE\":\""+voucherCode+"\"                    ");  
  40.             param.append("              }                   ");  
  41.             param.append("          }                   ");  
  42.             param.append("      }                   ");  
  43.             param.append("  }                   ");  
  44.   
  45.               
  46.             result = (String)call.invoke(new Object[]{param.toString()});    
  47.             //给方法传递参数,并且调用方法    
  48.             System.out.println("result is "+result);    
  49.         } catch (Exception e1) {    
  50.             e1.printStackTrace();    
  51.             MsgBox.showInfo("EAS核算凭证影像调阅接口调用失败");  
  52.             SysUtil.abort();  
  53.         }   
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();		}

转载地址:http://zedix.baihongyu.com/

你可能感兴趣的文章
Repost: Move semantics and smart pointers by Alex --- learncpp
查看>>
js中的 !! 和 ! 的区别
查看>>
ueditor内容带格式回显(html字符串回显)
查看>>
Mysql 函数
查看>>
spring源码-增强容器xml解析-3.1
查看>>
使用iSCSI Target创建集中式安全存储(一)
查看>>
18.一篇文章,从源码深入详解ThreadLocal内存泄漏问题
查看>>
Java网络编程和NIO详解7:浅谈 Linux 中NIO Selector 的实现原理
查看>>
CSS列表
查看>>
proc文件系统探索 之 根目录下的文件[1]
查看>>
Multi-Byte Character Set & Unicode Character Set
查看>>
int,NSInteger,NSUInteger,NSNumber
查看>>
linux并发控制之中断屏蔽
查看>>
檢查RAC狀態
查看>>
页面无刷新 省市二级联动
查看>>
spring boot 1.5.6版本整合LCN5.0
查看>>
今天给大家介绍下mysql简单优化
查看>>
Unity中的定时器与延时器
查看>>
【Visual C++】游戏开发笔记之五——游戏画面绘图(二)绘制位图
查看>>
解决Charles https抓包显示<unknown>
查看>>