疯狂

STANDING ON THE SHOULDERS OF GIANTS
posts - 481, comments - 486, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

axis webService发布webservice和client的简单实现

Posted on 2010-01-13 17:59 疯狂 阅读(2200) 评论(0)  编辑  收藏 所属分类: webservice
服务端:通过jws方式实现
  首先加入axis所需的jar 配置web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    
<display-name>vote</display-name>

    
<!-- Context Configuration locations for Spring XML files -->
 
<display-name>Apache-Axis</display-name>    
    
<listener>
        
<listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
    
</listener>
    
  
<servlet>
    
<servlet-name>AxisServlet</servlet-name>
    
<servlet-class>
        org.apache.axis.transport.http.AxisServlet
    
</servlet-class>
  
</servlet>

  
<servlet>
    
<servlet-name>AdminServlet</servlet-name>
    
<servlet-class>
        org.apache.axis.transport.http.AdminServlet
    
</servlet-class>
    
<load-on-startup>100</load-on-startup>
  
</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>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
  </servlet-mapping>

 
 
  <servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
  </servlet-mapping>
 
    <session-config>
        <session-timeout>20</session-timeout>
    </session-config>
  
  <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>

</web-app>

将接口文件实例内容如下:Test.jws
public class Test {


        
public String doRequest(String request){
        
//do
          return 
        }

}

将次文件放在WebRoot下 即可。

客户端,使用xfire实现
  首先拿到wsdl的url:webserviceUrl
通过  webServiceClient webServiceClient = new Client(new URL(webserviceUrl));创建客户端
然后就可以通过Object[] i = webServiceClient.invoke("webservers方法名", new Object[]{参数});来调用。





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


网站导航: