public static void main(String[] args){
try {
//XML解析後的字符串
String temp=new OrganisationWebServiceTest().readXml();
//webservice發佈地址
String endpoint = "http://localhost:8080/eHealth/services/IHisDrugMaterialWsService";
//實例化訪問對象
Service service = new Service();
//實例化調用對象
Call call = (Call)service.createCall();
//在調用對象中添加webservice地址
call.setTargetEndpointAddress(endpoint);
//在調用對象中添加將要調用的函數名(webservice對應的命名空間?)
call.setOperationName("saveMaterialInfo");
//設置入參,第一個參數是命名空間以及參數名,這兩個參數是採用一個Qname變量打包傳入的,第二個參數是入參的類型(字符或者數字)第三個參數是入參種類
call.addParameter("queryXml", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
//設置返回值格式(字符串或者組裝對象)
//給方法傳遞參數,並且調用方法
String result = (String) call.invoke(new Object[] { temp });
System.out.println("result is " + result);
}
catch (Exception e) {
// TODO Auto-generated catch block
System.err.println(e.toString());
}
}
//XML解析方法
private String readXml() {
StringBuffer sb=new StringBuffer();
try {
BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("C:\\material.xml"),"UTF-8"));
String line=null;
while((line=br.readLine())!=null){
sb.append(line);
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
}