本示例使用的是axis2
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(); }
- /**
- * 方法一:
- * 应用rpc的方式调用 这种方式就等于远程调用,
- * 即通过url定位告诉远程服务器,告知方法名称,参数等, 调用远程服务,得到结果。
- * 使用 org.apache.axis2.rpc.client.RPCServiceClient类调用WebService
- *
- 【注】:
- 如果被调用的WebService方法有返回值 应使用 invokeBlocking 方法 该方法有三个参数
- 第一个参数的类型是QName对象,表示要调用的方法名;
- 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[];
- 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}。
- 第三个参数表示WebService方法的 返回值类型的Class对象,参数类型为Class[]。
- 如果被调用的WebService方法没有返回值 应使用 invokeRobust 方法
- 该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同。
- 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,
- 也就是 <wsdl:definitions>元素的targetNamespace属性值。
- *
- */