標籤:
JAVA代碼如下:
static void testTextString() {
try {
String methodSayTo = "test";
// 定義服務
Service service = new Service();
Call call2 = (Call) service.createCall();
call2.setTargetEndpointAddress(new java.net.URL("http://localhost:21972/Service1.asmx")); //.net websevice地址
call2.setUseSOAPAction(true);
call2.setReturnType(new QName("http://www.w3.org/2001/XMLSchema","string"));
// 第二種設定返回值類型為String的方法
call2.setOperationName(new QName("http://192.168.40.133.org/",methodSayTo)); //命名空間
call2.setSOAPActionURI("http://192.168.40.133.org/test"); //命名空間+函數名
call2.addParameter(new QName("http://192.168.40.133.org/", "name"),// 這裡是.net webservice的形參名
XMLType.XSD_STRING, ParameterMode.IN);
String retVal2 = (String) call2
.invoke(new Object[] { "asp webservice" }); //asp webservice為要傳遞的字串
System.out.println(retVal2);
} catch (Exception e) {
// TODO: handle exception
}
}
參考文章如下:http://blog.csdn.net/xw13106209/article/details/7067495
java 調用.net webservice