axis實現webservices分布式通訊

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   java   for   


分布式通訊原理

 


基本原理:stub和skeleton作為用戶端和服務端傳輸的中介,stub和skeleton也是編碼和解碼的核心。 


Wsdl :

     Webservices描述檔案;xml定義的一套Webservices標準,描述服務端對應方法,參數以及返回值。可根據配置產生對應操作類。

 

其他常見的webservices實現

 

Corba


相對與webservices.編程複雜,而傳輸快。


UDDI

 

簡單來講,uddi中主要還是利用註冊中心。服務端通過註冊中心發送資料給對應的client,順便告知對應的client資料轉送到註冊中心的資訊。這樣來講,有這樣一個中介也避通過協議來直接傳輸龐大資料的缺點。

 

UDDI:http://blog.sina.com.cn/s/blog_645f168c0100i9pj.html

 

axis配置

 

一.配置webservice

 

1.將axis引擎部署到tomcat中。


axis-1_4\webapps\axis檔案夾複製到apache-tomcat-7.0.54-windows-x64\apache-tomcat-7.0.54\webapps下。


2.編輯對應的java類到axis中,並重新啟動tomcat


建立jws


publicclass MyWebService{publicString sayHello(String x){return"helloaxis"+x;                }}


儲存到axis根目錄


3.訪問對應http://localhost:8080/axis/MyWebService.jws


   Click to see the WSDL,看到MyWebService.jws對應的xml檔案。相當於一個反向工程,通常情況下利用這個xml檔案即可產生對應的java代碼。


至此webservices環境配置完成



 

二.驗證調用

 

1.匯入.jar

\axis-1_4\lib下的jar全部匯入




2.client調用
publicstatic void main(String[] args){//指明服務所在位置Stringurl="http://localhost:8080/axis/MyWebService.jws?wsdl";//axis對應服務Serviceservice =new Service();try{//為Call設定服務的位置Callcall=(Call)service.createCall();call.setTargetEndpointAddress(newURL(url));try{Stringrs=(String) call.invoke("sayHello", new Object[] {"cfl"});System.out.print(rs);}catch (AxisFault e) {//TODO Auto-generated catch blocke.printStackTrace();                        } }catch(ServiceExceptione){e.printStackTrace();}catch (MalformedURLException e) {//TODO Auto-generated catch blocke.printStackTrace();}}


調式日誌

 

錯誤1.


Error compiling  無法訪問 java.lang.Object 

錯誤2.


java.lang.RuntimeException: No compiler found in your classpath!(you may need to add ‘tools.jar‘)


以上兩個錯誤,只需將jdk下的tools.jar以及dt.jar拷貝到axis的lib檔案下即可。


警告3.


-Unable to find required classes (javax.activation.DataHandler andjavax.mail.internet.MimeMultipart).

Attachmentsupport is disabled.

 

將activation.jar、mail.jar匯入到axis對應的lib即可,消除警告。

 

詳情操作:http://blog.csdn.net/chastel/article/details/2084076

 


 

後序

        Webservices作為異構語言之間共用或者說是交流的一種分布式技術,主要涉及到soap、wsdl等技術。wsdl是用來描述服務端調用對象的,soap則是用來傳輸資料的。另外以stub和skeleton來作為中介。另外,從個人角度來講分布式與遠程調用還是不一樣的,應該講Webservices是遠程調用的一種解決方案。文中是一個小的不能再小的demo,原理如此,實際運用還需要再做研究。


        axis的另外幾種實現:http://www.cnblogs.com/mingzi/archive/2009/03/22/1419120.html

 

axis實現webservices分布式通訊

聯繫我們

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