webservice的远程调用方法

本示例使用的是axis2



 
 
  1. /** 
  2.    * 方法一: 
  3.    * 应用rpc的方式调用 这种方式就等于远程调用, 
  4.    * 即通过url定位告诉远程服务器,告知方法名称,参数等, 调用远程服务,得到结果。 
  5.    * 使用 org.apache.axis2.rpc.client.RPCServiceClient类调用WebService 
  6.    * 
  7.     【注】: 
  8.      
  9.         如果被调用的WebService方法有返回值 应使用 invokeBlocking 方法 该方法有三个参数 
  10.           第一个参数的类型是QName对象,表示要调用的方法名; 
  11.           第二个参数表示要调用的WebService方法的参数值,参数类型为Object[]; 
  12.             当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}。 
  13.           第三个参数表示WebService方法的 返回值类型的Class对象,参数类型为Class[]。 
  14.          
  15.          
  16.         如果被调用的WebService方法没有返回值 应使用 invokeRobust 方法 
  17.           该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同。 
  18.  
  19.         在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名, 
  20.         也就是 <wsdl:definitions>元素的targetNamespace属性值。 
  21.    * 
  22.    */ 
try{ RPCServiceClient client = new RPCServiceClient(); Options options = client.getOptions(); String url = "http://172.16.8.168:8061/itp?wsdl"; EndpointReference end = new EndpointReference(url); options.setTo(end); //确定调用方法 // options.setAction("urn:upLoadFile"); String filename="D:\\ftp\\ftpTest\\123.txt"; File file=new File(filename); TestService ts= new TestService(); String fileString=ts.readLocalFile(file); Object[] obj = new Object[]{file.getName(),fileString}; Class<?>[] classes = new Class[] { boolean.class }; QName qname = new QName("http://webservice.stp.hzih.com/", "upLoadFile"); // RPCServiceClient类的invokeBlocking方法调用了WebService中的方法。 invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象, 表示要调用的方法名;第二个参数表示要调用的WebService方法的参数值, 参数类型为Object[];第三个参数表示WebService方法的返回值类型的Class对象, 参数类型为Class[]。当方法没有参数时,invokeBlocking方法的第二个参数值不能是null, 而要使用new Object[]{}。   Object[] response = client.invokeBlocking(qname, obj,classes); boolean result=(boolean)response[0]; System.out.println(result); }catch(AxisFault e){ e.printStackTrace(); }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值