Web Service之Axis起步

(1)配置axis,需要下载3个jar文件:activation.jar、mail.jar和xmlsec.jar。

(2)部署HelloWorld.jws文件(内容如下),提示“java.lang.RuntimeException: No compiler found in your classpath! (you may need to add 'tools.jar')”,将tools.jar和dt.jar文件从jdk拷贝至Tomcat 5.5/common/lib,解决。

public   class  HelloWorld  {
    
public String sayHello(String name){
        
return "axis say hello:" + name;
    }

}

(3)使用tcp monitor观察soap消息交换情况。 

F:/Apache Software Foundation/Tomcat 5.5/webapps/axis>java org.apache.axis.utils
.tcpmon 8081 localhost 8080

request和response消息如下:


==============
Listen Port: 8081
Target Host: localhost
Target Port: 8080
==== Request ====
POST /axis/HelloWorld.jws HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8081
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 445

<? xml version="1.0" encoding="UTF-8" ?>    
   
< soapenv:Envelope  xmlns:soapenv ="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd ="http://www.w3.org/2001/XMLSchema"  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" >       
      
< soapenv:Body >          
         
< sayHello  soapenv:encodingStyle ="http://schemas.xmlsoap.org/soap/encoding/" >             
            
< param1  xsi:type ="xsd:string" > sun </ param1 >          
         
</ sayHello >       
      
</ soapenv:Body >    
   
</ soapenv:Envelope > ==== Response ====
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=9BFB75F7ADD1D9475DE9CEA3EB8724E9; Path=/axis
Content-Type: text/xml;charset=utf-8
Date: Sat, 06 Jan 2007 13:33:04 GMT
Connection: close

<? xml version="1.0" encoding="utf-8" ?>
   
< soapenv:Envelope  xmlns:soapenv ="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd ="http://www.w3.org/2001/XMLSchema"  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" >
      
< soapenv:Body >
         
< sayHelloResponse  soapenv:encodingStyle ="http://schemas.xmlsoap.org/soap/encoding/" >
            
< sayHelloReturn  xsi:type ="xsd:string" > axis say hello:sun </ sayHelloReturn >
         
</ sayHelloResponse >
      
</ soapenv:Body >
   
</ soapenv:Envelope >
==============

(4)使用wsdd(Web Service Deployment Descriptor,Web服务部署描述语言)部署服务,主要有两点:

a. 修改axis自带的“server-config.wsdd”文件,添加自定义的服务。

b.添加axis自带的web.xml文件。

这样,访问http://localhost:8080/test/services

就可以看到自己的服务了。

详细配置可参考:http://www.cnblogs.com/bjzhanghao/archive/2004/10/09/50216.aspx

你可能感兴趣的:(Web Service之Axis起步)