Posted on 2006-11-28 21:00
Zou Ang 閱讀(755)
評論(1) 編輯 收藏 所屬分類:
今天在宿舍,用Axis來弄了個最簡單的Web Service.先來講下怎么安裝和部署.
首先,去Apache的網(wǎng)站下載Axis,我沒有下載Axis2,因為據(jù)說Axis2和Axis有比較多的不同,所以還是覺得先用以前的吧.
下載好了以后,把axis下的webapp文件夾中的axis放到tomcat的webapp目錄下,然后啟動tomcat,輸入:http://localhost:8080/axis/,如果成功會看到歡迎頁面.
然后寫一個Java類:
import?java.util.HashMap;
import?java.util.Map;


/**?*//**
?*?2006-11-28
?*?@author?Zou?Ang
?*?Contact?<a?href?="mailto:richardeee@gmail.com">Zou?Ang</a>
?*/

public?class?BookTitleService?
{

????Map<String,String>?books;

????public?BookTitleService()
{
????????books?=?new?HashMap<String,String>();
????????
????????books.put("0130895601","Advanced?Java?2?Platform?How?to?Program");
????????books.put("0430895717","C++?How?to?Program,Third?edition");
????????books.put("0430293636","Visual?Basic.?NET?How?to?Program");
????????books.put("0130923613","Python?How?to?Program");
????}
????

????public?String?getBookTitle(String?ISBN)
{
????????return?books.get(ISBN);
????}
}然后把BookTitleService.java更名為BookTitleService.jws,把更改后的文件放到%CATALINA_HOME%/webapps/axis/%包結(jié)構(gòu)(比如org/apache/..)/目錄下
,我的是D:\apache-tomcat-5.5.17\apache-tomcat-5.5.17\webapps\axis\org\zsu\zouang\BookTitleService.jws,注意,這樣放好了jws文件后,把java類中的包名要刪除,做完了以后重新啟動tomcat,在地址欄輸入
http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws,如果Web服務(wù)部署成功就會有頁面顯示的了,點Click to See WSDL后,可以看到:
?<?xml?version="1.0"?encoding="UTF-8"??>?
-?<wsdl:definitions?targetNamespace="http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws"?xmlns:apachesoap="http://xml.apache.org/xml-soap"?xmlns:impl="http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws"?xmlns:intf="http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws"?xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"?xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"?xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"?xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-?<!--?
WSDL?created?by?Apache?Axis?version:?1.4
Built?on?Apr?22,?2006?(06:55:48?PDT)

??-->?
-?<wsdl:message?name="getBookTitleRequest">
??<wsdl:part?name="ISBN"?type="xsd:string"?/>?
??</wsdl:message>
-?<wsdl:message?name="getBookTitleResponse">
??<wsdl:part?name="getBookTitleReturn"?type="xsd:string"?/>?
??</wsdl:message>
-?<wsdl:portType?name="BookTitleService">
-?<wsdl:operation?name="getBookTitle"?parameterOrder="ISBN">
??<wsdl:input?message="impl:getBookTitleRequest"?name="getBookTitleRequest"?/>?
??<wsdl:output?message="impl:getBookTitleResponse"?name="getBookTitleResponse"?/>?
??</wsdl:operation>
??</wsdl:portType>
-?<wsdl:binding?name="BookTitleServiceSoapBinding"?type="impl:BookTitleService">
??<wsdlsoap:binding?style="rpc"?transport="http://schemas.xmlsoap.org/soap/http"?/>?
-?<wsdl:operation?name="getBookTitle">
??<wsdlsoap:operation?soapAction=""?/>?
-?<wsdl:input?name="getBookTitleRequest">
??<wsdlsoap:body?encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"?namespace="http://DefaultNamespace"?use="encoded"?/>?
??</wsdl:input>
-?<wsdl:output?name="getBookTitleResponse">
??<wsdlsoap:body?encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"?namespace="http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws"?use="encoded"?/>?
??</wsdl:output>
??</wsdl:operation>
??</wsdl:binding>
-?<wsdl:service?name="BookTitleServiceService">
-?<wsdl:port?binding="impl:BookTitleServiceSoapBinding"?name="BookTitleService">
??<wsdlsoap:address?location="http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws"?/>?
??</wsdl:port>
??</wsdl:service>
??</wsdl:definitions>這樣,一個最最簡單的Web Service就部署成功了.