導航:首頁 > 編程語言 > java獲取webservice

java獲取webservice

發布時間:2023-10-17 02:22:36

① 怎麼使用java調用siebel 的webservice介面

整個過程還是比較簡單的:

1、用SOAP UI工具測試你發布的東西到底是否可以執行

② 跪求一個最原始最通用的Java調用webservice的方法

再原始的也得先選個庫啊,jdk里本身又沒有訪問webservice的庫
比如commons-httpclient-3.1.jar里的HttpClient、xfire,axis,cxf等
比如,我一直是用cxf訪問webservice的(不考慮提供方語言,就算是.net提供的webservice也一樣)
CXF調用webservice步驟(我認為這個最簡單,因為不需要你寫代碼)

1、下載CXF,並將cxf的bin目錄加入到操作系統環境變數中(或者直接使用cmd命令進入CXF的bin文件夾
2、將wsdl文件放到某個目錄下(如果沒有設置環境變數,則將此wsdl文件放入CXF的bin文件夾),執行命令wsdl2java -impl xxx.xml,則生成了符合wsdl要求的伺服器端代碼
3、在生成好的代碼里尋找xxx.xml,刪除或修改掉這些代碼即可(構造函數的URL屬性修改為http://形式的字元串,比如http://127.0.0.1/xxx?wsdl,其他部分出現的xxx.xml全部刪除)

③ Java客戶端調用Webservice介面流程

給你看看以前寫的獲取電話號碼歸屬地的代碼的三種方法,然後你就懂了。

importjava.io.ByteArrayOutputStream;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.net.HttpURLConnection;
importjava.net.URL;

importorg.apache.commons.httpclient.HttpClient;
importorg.apache.commons.httpclient.HttpException;
importorg.apache.commons.httpclient.methods.PostMethod;

publicclassMobileCodeService{

publicvoidhttpGet(Stringmobile,StringuserID)throwsException
{
//http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode=string&userID=string
URLurl=newURL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="+mobile+"&userID="+userID);
HttpURLConnectionconn=(HttpURLConnection)url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");

if(conn.getResponseCode()==HttpURLConnection.HTTP_OK)//200
{
InputStreamis=conn.getInputStream();

=newByteArrayOutputStream();//

byte[]buf=newbyte[1024];
intlen=-1;
while((len=is.read(buf))!=-1)
{
//獲取結果
arrayOutputStream.write(buf,0,len);
}

System.out.println("Get方式獲取的數據是:"+arrayOutputStream.toString());
arrayOutputStream.close();
is.close();
}
}


publicvoidhttpPost(Stringmobile,StringuserID)throwsHttpException,IOException
{
//訪問路徑http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo
//HttpClient訪問

HttpClienthttpClient=newHttpClient();
PostMethodpm=newPostMethod("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo");

pm.setParameter("mobileCode",mobile);
pm.setParameter("userID",userID);

intcode=httpClient.executeMethod(pm);
System.out.println("狀態碼:"+code);

//獲取結果
Stringresult=pm.getResponseBodyAsString();
System.out.println("獲取到的數據是:"+result);
}

publicvoidSOAP()throwsException
{
HttpClientclient=newHttpClient();

PostMethodmethod=newPostMethod("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx");

//設置訪問方法的參數
method.setRequestBody(newFileInputStream("C:\soap.xml"));

method.setRequestHeader("Content-Type","text/xml;charset=utf-8");

intcode=client.executeMethod(method);
System.out.println("狀態碼:"+code);

//獲取結果
Stringresult=method.getResponseBodyAsString();
System.out.println("獲取到的數據是:"+result);
}

publicstaticvoidmain(String[]args)throwsException{
MobileCodeServicemcs=newMobileCodeService();
mcs.httpGet("18524012513","");
//mcs.httpPost("18524012513","");
//mcs.SOAP();
}
}
閱讀全文

與java獲取webservice相關的資料

熱點內容
海康威視sip伺服器地址 瀏覽:163
挖掘機程序員哪個好 瀏覽:458
方舟怎麼進上一次進的伺服器 瀏覽:635
pdf怎樣剪切 瀏覽:906
git編譯所有文件命令 瀏覽:694
偽軍pdf 瀏覽:418
如何判斷基本命令 瀏覽:972
pdf批量刪除 瀏覽:943
廣播android靜態動態區別 瀏覽:390
centos7設置為命令行啟動 瀏覽:570
程序員資質資格證 瀏覽:217
常見編碼加密 瀏覽:236
阿狸免費雲伺服器 瀏覽:764
快速配置伺服器bmc地址 瀏覽:968
機械手臂編程自動化 瀏覽:501
怎麼看銀行app的銀行卡號 瀏覽:84
pdf文件改ppt 瀏覽:196
ecs對比雲伺服器 瀏覽:852
必剪app怎麼沒有美顏 瀏覽:176
唯庫的視頻怎麼下載app 瀏覽:465