posts - 32, comments - 153, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Web Service学习日记-11月28日-Web Service部署

Posted on 2006-11-28 21:00 Zou Ang 阅读(732) 评论(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.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/%包结构(比如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" ?> 
<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就部署成功了.

评论

# re: Web Service学习日记-11月28日-Web Service部署  回复  更多评论   

2006-11-28 22:47 by Tauruser
最最最简单啊!
加油。
排版好宽-_-

只有注册用户登录后才能发表评论。


网站导航: