日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

asmx结尾接口调用

發(fā)布時間:2023/12/29 综合教程 38 生活家
生活随笔 收集整理的這篇文章主要介紹了 asmx结尾接口调用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

public static String callService(String method , String params ,String paramsName){

String url = "xxx.asmx";// 提供接口的地址

String soapaction = "http://tempuri.org/"; //這個由接口提供者提供

Service service = new Service();

String result = "";

try{

Call call = (Call) service.createCall();

call.setTargetEndpointAddress(url);

call.setOperationName(new QName(soapaction, method)); // 設(shè)置要調(diào)用哪個方法

call.addParameter(new QName(soapaction, paramsName), // 設(shè)置要傳遞的參數(shù)--要和接口方提供的參數(shù)名一致

org.apache.axis.encoding.XMLType.XSD_STRING,

javax.xml.rpc.ParameterMode.IN);

call.setReturnType(new QName(soapaction, method), String.class); // 要返回的數(shù)據(jù)類型

call.setUseSOAPAction(true);

call.setSOAPActionURI(soapaction + method);

result = (String) call.invoke(new Object[] { params });// 調(diào)用方法并傳遞參數(shù)

System.out.print("接口返回信息:"+result);

}catch (Exception ex){

ex.printStackTrace();

}

return result;

}

備注:method 接口方法

   params 接口參數(shù)

   paramsName 接口參數(shù)名

public static String callService1(String method , String params ,String paramsName){String result = null;try { String endpoint = "http://122.227.252.10:5555/U9Interface/OAService.asmx?wsdl"; //直接引用遠(yuǎn)程的wsdl文件 //以下都是套路 Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(endpoint); call.setSOAPActionURI("http://tempuri.org/"+method); call.setOperationName(new QName("http://tempuri.org",method));//WSDL里面描述的接口名稱 call.addParameter(new QName("http://tempuri.org",paramsName), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);//接口的參數(shù) call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//設(shè)置返回類型 call.setUseSOAPAction(true); result = (String) call.invoke(new Object[]{params});//給方法傳遞參數(shù),并且調(diào)用方法 System.out.println("測試接口:"+result); } catch (Exception e) { System.err.println(e.toString()); }return result;

總結(jié)

以上是生活随笔為你收集整理的asmx结尾接口调用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。