1. 程式人生 > >使用axis1.4生成webservice的客戶端程式碼

使用axis1.4生成webservice的客戶端程式碼

最近發現了一個很好用的工具,可以根據WSDL檔案來生成webservice客戶端程式碼,省去了我們自己手動開發webservice客戶端的麻煩,簡單好用,用法如下:

1、下載axis1.4,解壓;
2、在axis-1_4目錄下新建wsdl2java-client.bat(.bat批處理檔案,可任意命名)檔案,增加內容如下:

set Axis_Lib=.\lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java   -p com.lmb.client.ws C:\Users\Administrator\Desktop\axis-1
_4\axis-1_4\lmbtest.xml pause

注意:其中com.lmb.client.ws為生成的客戶端程式碼的包路徑,C:\Users\Administrator\Desktop\axis-1_4\axis-1_4\lmbtest.xml為wsdl檔案。

3、雙擊wsdl2java-client.bat:
這裡寫圖片描述
可以看到相關路徑下生成的客戶端程式碼如下:
這裡寫圖片描述

4、呼叫方法如下:

public class WebServiceClientTest{
    public static void main(String[] args){
        String wsdl = "http://xxx.xxx.xx.xx:8082/csp/services/c_lttb/orderToHeLiWebservice"
; String requestStr = ""; // 有些webservice需要登入,登陸後才能進行一些操作,這個需要設定如下兩個引數: //1、 超時時間 stub.setTimeout(1000 * 60 * 20); //2、 次數設定true,登入後才能保持登入狀態,否則第二次呼叫ws方法時仍然會提示未登入。 stub.setMaintainSession(true); org.apache.axis.client.Service service = new org.apache.axis.client.Service(); OrderToHeLiWebserviceHttpBindingStub stub = new
OrderToHeLiWebserviceHttpBindingStub( new java.net.URL(wsdl), service); String response = stub.urgeWorkOrderServiceSheet(requestStr); //呼叫ws提供的方法 System.out.println("response >>> " + response); } }