用Axis開發Webservice

來源:互聯網
上載者:User
Axis是Apache的一個開源web service引擎。它目前最為成熟的開源web service引擎之一。下面我主要介紹一下如何使用該Axis開發您的web service 服務。
1.安裝

以tomcat4.1為伺服器,下面說明如何安裝axis:
   1.解壓下載後的包,將包中axis目錄複寫到tomcat目錄下的webapps目錄下;
   2.將axis/WEB-INF/lib目錄下類檔案複製到tomcat目錄下的common/lib目錄下;
   3.重新啟動tomcat;
   4.訪問http://localhost:8080/axis/happyaxis.jsp,如果能訪問,表示安裝成功;
2.開發webservice服務

a.編寫普通類檔案,如下所示://檔案名稱:Test.java
import java.util.*;

public class Test{
    //fields
    private    String name="gaga";
    private int age=20;
    private List items=new ArrayList();
    
    
    //method at here.
    public String getName(){
        return name;
    }
    
    public int getAge(){
        return age;
    }
    
    public List getItems(){
        return items;
    }
}

將本檔案(Test.java)複製到Axis目錄下,並將其更名為Test.jws;
b.訪問http://localhost:8080/axis/Test.jws,Axis就會編譯該檔案,並將其部署到系統中;
下面你就可以開發web service的用戶端程式了;

3.開發用戶端程式

下面是用戶端程式:import org.apache.axis.client.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;


public class TestWebService{
    
    public static void main(String args[]){
        
        System.out.println("Start invoking.");
        
         try {
             String endpoint =
                      "http://localhost:8080/axis/Test.jws";//你寫的那個檔案
        
             Service  service = new Service();
             Call     call    = (Call) service.createCall();
        
             call.setTargetEndpointAddress( new java.net.URL(endpoint) );
             call.setOperationName("getAge");//填寫你要調用的方法名稱
        
             int ret =Integer.parseInt(("" + call.invoke( new Object[] {} )));
            
            System.out.println(ret);
             
         } catch (Exception e) {
             System.err.println(e.toString());
         }
    
        
        System.out.println("Finished the invoking.");        
        
    }
    
}

關於業務調用封裝到服務端程式裡,然後部署就可以了,就這麼簡單。
4.資源

http://ws.apache.org/axis/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.