webservice的使用-axis1

來源:互聯網
上載者:User

標籤:alt   []   logs   tomcat   下界   1.2   記憶體   .com   一個   

1.搭建axis伺服器

  1.1 下載axis-bin-1_4.zip檔案並解壓

  1.2 拷貝\axis-1_4\webapps目錄下的axis到tomcat目錄下的webapps目錄下並啟動

  1.3 在瀏覽器中輸入http://localhost:8080/axis/ 如果能進入到axis首頁就表示是搭建成功

    

2.發布自己的應用到axis伺服器(即時發布和定製發布)

  2.1 即時發布(僅適用於單個java檔案,且沒有包和jar包,且需要有源碼)(jws)

    發布步驟:

      1)編寫單個java檔案

public class HelloWS {    public String hello(String a,String b) {        return "response by server "+a +","+b    }}

       2)將HelloWS.java拷貝到tomcat下的webapps/axis目錄下,並改名為HelloWS.jws,重啟tomcat

        

      3 )在瀏覽器中輸入http://localhost:8080/axis/HelloWS.jws看到以下介面表示發布成功

        

      4) 點擊的Click to see the WSDL如果報以下錯誤,修改jdk的版本為1.6(本人測試,不支援1.8)

        

  2.2 定製發布(WSDD)

    2.2.1 帶有包結構的class檔案進行發布

      1) 編寫java代碼並進行編譯為為class檔案      

package com.beifeng.hadoop.webservice.server;
public class HelloWSDD { private int counter=0; public String hello(String name) { counter++; System.out.println("訪問次數:"+counter); return "歡迎訪問axis伺服器:"+name; } public float add(float a,float b) { counter++; System.out.println("訪問次數:"+counter); return a+b; }}

       2) 將編譯後的class檔案及包結構拷貝到tomcat\webapps\axis\WEB-INF\classes目錄下

        

      3)在axis\WEB-INF\server-config.wsdd檔案中添加要發布的服務,如果沒有該檔案在其他地方進行拷貝   

  <!--要發布的服務名稱 -->
  <service name="HelloWSDD" provider="java:RPC">
     <!--類名--> <parameter name="className" value="com.beifeng.hadoop.webservice.server.HelloWSDD" />
     <!--要發布的方法--> <parameter name="allowedMethods" value="hello,add" />
     <parameter name="scope" value="application"/>  </service>

      參數scope的值:requet、session或application

      request:Axis為每一個SOAP的請求產生一個服務物件,針對於請求(預設)

       session:Axis為每一個調用webservice的用戶端產生一個對象,針對於會話

      application:在伺服器記憶體中直接建立一個對象,每次請求直接返回

    4)重啟tomcat,在瀏覽器中輸入http://location:8080,點擊list即可看到如下頁面

      

3. 用戶端調用

  3.1 調用jws即時發布的HelloWS.jws的hello方法

//服務地址String url="http://localhost:8080/axis/HelloWS.jws";        //構建web service 服務Service service=new Service();        //建立一個調用Call call=(Call) service.createCall();         //設定調用的地址call.setTargetEndpointAddress(url);        //設定要調用的方法call.setOperationName(new QName(url, "hello"));        //執行該調用並傳遞參數String result=(String) call.invoke(new Object[]{"teacher","student"});        //返回結果:response by server teacher,studentSystem.out.println(result);

 

 

 

 

 

 

  

 

webservice的使用-axis1

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.