Posted on 2006-11-28 21:00 
Zou Ang 阅读(783) 
评论(1)  编辑  收藏  所属分类: 
 
 
			 
			
		 
		今天在宿舍,用Axis来弄了个最简单的Web Service.先来讲下怎么安装和部署.
首先,去Apache的网站下载Axis,我没有下载Axis2,因为据说Axis2和Axis有比较多的不同,所以还是觉得先用以前的吧.
下载好了以后,把axis下的webapp文件夹中的axis放到tomcat的webapp目录下,然后启动tomcat,输入:http://localhost:8080/axis/,如果成功会看到欢迎页面.
然后写一个Java类:
 import java.util.HashMap;
import java.util.HashMap;
 import java.util.Map;
import java.util.Map;


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

 public class BookTitleService
public class BookTitleService  {
{

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

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

 public String getBookTitle(String ISBN)
    public String getBookTitle(String ISBN) {
{
 return books.get(ISBN);
        return books.get(ISBN);
 }
    }
 }
}然后把BookTitleService.java更名为BookTitleService.jws,把更改后的文件放到%CATALINA_HOME%/webapps/axis/%包结构(比如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服务部署成功就会有页面显示的了,点Click to See WSDL后,可以看到:
 <?xml version="1.0" encoding="UTF-8" ?>
 <?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: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
WSDL created by Apache Axis version: 1.4
 Built on Apr 22, 2006 (06:55:48 PDT)
Built on Apr 22, 2006 (06:55:48 PDT)

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