Eclipse下使用Axis开发webservice
 

1.1.       拷贝一些必要的文件

1.     将axis下的server-config.wsdd拷贝到myeclipse的web project的WEB-INF下。
2.     导入第三方包到工程下的lib目录

1.2.       设定servlet控制器

修改WEB-INF下的web.xml文件,添加以下内容:
 
< servlet >

    
< servlet-name > AxisServlet servlet-name >

< servlet-class > org.apache.axis.transport.http.AxisServlet servlet-class >

 
servlet >

 

   
< servlet >

    
< servlet-name > SOAPMonitorService servlet-name >

< servlet-class > org.apache.axis.monitor.SOAPMonitorService servlet-class >

    
< init-param >

      
< param-name > SOAPMonitorPort param-name >

      
< param-value > 5001 param-value >

    
init-param >

    
< load-on-startup > 100 load-on-startup >

 
servlet >

 
< servlet-mapping >

    
< servlet-name > AxisServlet servlet-name >

   
< url-pattern > /servlet/AxisServlet url-pattern >

 
servlet-mapping >

 

 
< servlet-mapping >

    
< servlet-name > AxisServlet servlet-name >

    
< url-pattern > *.jws url-pattern >

 
servlet-mapping >

 

 
< servlet-mapping >

    
< servlet-name > AxisServlet servlet-name >

    
< url-pattern > /services/* url-pattern >

 
servlet-mapping >

 
< servlet-mapping >

    
< servlet-name > AxisServlet servlet-name >

    
< url-pattern > /ws/* url-pattern >

 
servlet-mapping >

 

 
< servlet-mapping >

    
< servlet-name > SOAPMonitorService servlet-name >

    
< url-pattern > /SOAPMonitor url-pattern >

 
servlet-mapping >

 

 
< mime-mapping >

    
< extension > wsdl extension >

     
< mime-type > text/xml mime-type >

 
mime-mapping >

 
< mime-mapping >

    
< extension > xsd extension >

    
< mime-type > text/xml mime-type >

 
mime-mapping >
 
 

1.3.       添加要发布的服务

添加要发布的服务到server-config.wsdd。如:
 
< service  name ="wsServerTest"  provider ="java:RPC"  style ="rpc"  use ="encoded" >

        
< namespace > com.xxxxx.ws namespace >

        
< parameter  name ="wsdlServiceElement"  value ="webserviceTest" />

        
< parameter  name ="wsdlPortType"  value ="webserviceTest" />

        
< parameter  name ="className"  value ="com.xxxxx.ws.server.ServerTestFacadeImpl" />

        
< parameter  name ="allowedMethods"  value ="*" />

service >
 
 

1.4.       使用java2wsdl生成wsdl

用axis的java2wsdl类来生成wsServerTest.wsdl:
选择项目,选择或者填入main函数org.apache.axis.wsdl.Java2WSDL
在run的程序参数设置为:
-o wsServerTest.wsdl
-l "[url]http://localhost:8080/myproject/services/wsServerTest"[/url]
-n "urn:wsServerTest"
-p"com.xxxxx.ws.server" "urn:wsServerTest"
com.xxxxx.ws.server.ServerTestFacade
 

1.5.       使用wsdl2java生成stub

用axis的wsdl2java来生成stub:
选择项目,选择或者填入main函数org.apache.axis.wsdl.WSDL2Java
在run的程序参数设置为:
D:\program\Eclipse3.2\wsSeverTest\wsServerTest.wsdl -t -p com.xxxxx.ws.client
 

1.6.       客户端测试

如果是安全通道,将client.keystore和client.truststore放到wsClientTest工程下。在vm 参数设定:
-Djavax.net.ssl.keyStore=D:\program\Eclipse3.2\wsClientTest\client.keystore
-Djavax.net.ssl.keyStorePassword=changeit
-Djavax.net.ssl.trustStore=D:\program\Eclipse3.2\wsClientTest\client.truststore
将url改为https:localhost:8443/myproject/services/wsServerTest来调用发布的函数。