axis2+myeclipse6.0發布java webservice

來源:互聯網
上載者:User

 

1.首先在myeclipse裝axis2外掛程式,比較麻煩,各種狀況。

參照了:http://blog.csdn.net/seven_zhao/article/details/6089747

 

2.axis2.jar包下載,地址:http://axis.apache.org/axis2/java/core/download.cgi ,我用的版本是1.5.6

 

3.產生伺服器端工程yourProjectName

參照了:http://www.lifeba.org/arch/java_axis2_webservice.html 使用第三部分:獨立部署中的方法。

主要是複製WEB-INFO下的3個axis2相關檔案夾和web.xml,然後修改services.xml裡邊的服務名稱yourServiceName和方法名稱yourMethod。

如:服務類TestWs:

package ws;public class TestWs {public String showName(String name) {return name;}public String getName() {return "Hello,Axis2,,by getName method.";}}

services.xml配置如下:

<service name="AxisService"><description>AxisService</description><parameter name="ServiceClass">ws.TestWs</parameter><operation name="showName"><messageReceiverclass="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /></operation><operation name="getName"><messageReceiverclass="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /></operation></service>

 

工程名稱為Axis2Service

部署在tomcat下驗證服務是否正常:

http://localhost:81/yourProjectName/services/yourServiceName?wsdl

http://localhost:81/Axis2Service/services/AxisService?wsdl

 

4.產生用戶端測試程式

使用裝好的axis2外掛程式“Axis2 Code Generator” 產生代碼到指定工程下。

測試類別:

package test;import ws.AxisServiceStub;public class ClientTest {public static void main(String[] args) throws Exception {AxisServiceStub stub = new AxisServiceStub();AxisServiceStub.ShowName command = new AxisServiceStub.ShowName();command.setName("Hello,axis2,,by showName method.");String showNameRtn = stub.showName(command).get_return();System.out.println(showNameRtn);String getNameRtn = stub.getName().get_return();System.out.println(getNameRtn);}}

輸出:

Hello,axis2,,by showName method.
Hello,Axis2,,by getName method.

 

聯繫我們

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