java 呼叫webservice asmx
阿新 • • 發佈:2019-01-09
String inputParam = "測試";
Service service = new Service();
String url = "http://xxxxxxx/service/getinfo.asmx"; //URL地址
String namespace = "http://tempuri.org/";
String actionUri = "getinfo"; //Action路徑
String op = "getinfo"; //要呼叫的方法名
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java .net.URL(url));
call.setUseSOAPAction(true);
call.setSOAPActionURI(namespace + actionUri); // action uri
call.setOperationName(new QName(namespace, op));// 設定要呼叫哪個方法
// 設定引數名稱,具體參照從瀏覽器中看到的
call.addParameter(new QName(namespace, "strMac"), XMLType.XSD_STRING, ParameterMode.IN); //設定請求引數及型別
//call.setReturnType(new QName(namespace,"getinfo"),Model.class); //設定返回結果為是某個類
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//設定結果返回型別
Object[] params = new Object[] {inputParam};
String result = (String) call.invoke(params); //方法執行後的返回值
System.out.println(result);
return result;
}
Service service = new Service();
String url = "http://xxxxxxx/service/getinfo.asmx"; //URL地址
String namespace = "http://tempuri.org/";
String actionUri = "getinfo"; //Action路徑
String op = "getinfo"; //要呼叫的方法名
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java
call.setUseSOAPAction(true);
call.setSOAPActionURI(namespace + actionUri); // action uri
call.setOperationName(new QName(namespace, op));// 設定要呼叫哪個方法
// 設定引數名稱,具體參照從瀏覽器中看到的
call.addParameter(new QName(namespace, "strMac"), XMLType.XSD_STRING, ParameterMode.IN); //設定請求引數及型別
//call.setReturnType(new QName(namespace,"getinfo"),Model.class); //設定返回結果為是某個類
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//設定結果返回型別
Object[] params = new Object[] {inputParam};
String result = (String) call.invoke(params); //方法執行後的返回值
System.out.println(result);
return result;
}