Axis入門(4)

來源:互聯網
上載者:User

發布自己的WEB services服務

1)建立自己的JAVA檔案如下:
public class HelloService
{
?public String echoString(String name)
?{
??return name;
?}
}
2)將該檔案改名為HelloService.jws,copy 到D:/Tomcat 5.0/webapps/axis目錄下
3)啟動TOMCAT
4)編寫用戶端代碼如下:
package com.hongsoft.test;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;

public class TestClient
{
?? public static void main(String [] args) {
?????? try {
?????????? String endpoint="http://localhost:8080/axis/HelloService.jws";
????
?????????? Service? service = new Service();
?????????? Call???? call??? = (Call) service.createCall();

?????????? call.setTargetEndpointAddress( new java.net.URL(endpoint) );??????????
?????????? call.setOperationName(new QName("echoString") );
??????????
?????????? String ret = (String) call.invoke( new Object[] { "Hello!" } );

?????????? System.out.println("Sent 'Hello!', got '" + ret + "'");
?????? } catch (Exception e) {
?????????? System.err.println(e.toString());
?????? }
?? }
}
5)運行用戶端程式,效果如下:
?Sent 'Hello!', got 'Hello!'
Axis能夠自動定位檔案,編譯,並把SOAP調用轉化為對你的服務的JAVA調用.
6)是不是很簡單?是的,但你別高興太早了,我們要注意下面的問題:
? JWS web services只是用於簡單的WEB服務的,我們在服務代碼中不能用package,而且,代碼是在運行期

編譯的,不到發布階段,你找不到任何的錯誤提示資訊.我們將在後面討論其它的發布自己的WEB services服務的方法.

聯繫我們

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