可能會用到的調用web service的客戶端代碼
/*
JaxWsProxyFactoryBean proxyFactoryBean=new JaxWsProxyFactoryBean();
//設置訪問地址
proxyFactoryBean.setAddress("http://127.0.0.1:8089/user?wsdl");
//設置portType
proxyFactoryBean.setServiceClass(IUsersService.class);
//獲取服務對象
IUsersService usersService= (IUsersService) proxyFactoryBean.create();
usersService.getAge("李白");
Client client = new Client(new URL("http://127.0.0.1:8089/user?wsdl"));
Object[] results = client.invoke("getAge", new Object[] { "李白" });
System.out.println(results[0]);*/
}
/*try {
String endpoint = "http://localhost:8088/weather"; //直接引用遠程的wsdl文件
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
//call.setOperationName("getName");//wsdl裏面描述的接口名稱
call.addParameter("userId", XMLType.XSD_DATE, ParameterMode.IN);//接口的參數
call.setReturnType(XMLType.XSD_STRING);//設置返回類型
call.invoke("getName",new Object[]{10001});//給方法傳遞參數,而且調用方法
// System.out.println("result is " + result);
} catch (Exception e) {
e.printStackTrace();
}
}*/
}
/* JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://192.168.122.71:8000/services/resourceService?wsdl");
Object[] objects = new Object[0];
String param="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"http://serv.services.rs.idc.regaltec.com\" xmlns:types=\"http://serv.services.rs.idc.regaltec.com/encodedTypes\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
" <tns:queryRoom>\n" +
" <inputXml xsi:type=\"xsd:string\"><idcCenterCode>Mega_IDC_4</idcCenterCode></inputXml>\n" +
" </tns:queryRoom>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";
try {
objects = client.invoke("queryRoom", param);
} catch (Exception e) {
e.printStackTrace();
}
//輸出調用結果
System.out.println(objects[0].getClass());
System.out.println(objects[0].toString());
}*/
複製代碼