最近经常做接口集成,总结两种使用JAVA调用webservice服务的两种方式,生成本地客户端类调用就不说了。
第一种:
public static String testOAWebService(){ String result = ""; try { Client c = new Client(new URL("http://10.3.100.100/services/WorkflowService?wsdl")); Object[] params = new Object[5]; params[0]=null; params[1]=new Integer(1497276);//工作流请求ID params[2]=new Integer(26626);//空节点操作人ID params[3]="submit";//参数为reject时退回流程,为submit时提交流程 params[4]="手动测试OA接口";// Object[] results = c.invoke("submitWorkflowRequest", params); result = results[0].toString(); } catch (MalformedURLException e) { System.out.println(e); e.printStackTrace(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } System.out.println("result:"+result); return result; }
第二种:
public static String testOrg2(){
String endpoint= "http://10.3.100.198:8080/ccqc/services/unitSynService?wsdl";
String result = "";
Service service = new Service();
Call call;
try {
call=(Call)service.createCall();
call.setTargetEndpointAddress(endpoint);//远程调用路径
call.setOperationName("untilSynXml");//调用的方法名
//设置返回值类型:
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//返回值类型:String
result = (String)call.invoke(new Object[0]);//远程调用
System.out.println("result:"+result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}