axis webservice (server-config.wsdd)

需要的jar 包: axis-ant.jar,axis.jar,commons-discovery-0.2.jar,commons-loggin-1.0.4.jar,jaxrpc.jar,log4j-1.2.8.jar,saaj.jar,wsdl4j-1.5.1.jaar
简单些一个方法
WebService.java
/**
 * WebService.java
 * com.lewking.web
 *
 * Function: TODO 
 *
 *   ver         date      	    author
 * ──────────────────────────────────────
 *  Ver 1.1	     2011-6-8 	    lewking
 *
 * Copyright (c) 2011, TNT All Rights Reserved.
*/

package com.lewking.web;
/**
 * ClassName:WebService
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   lewking
 * @version  
 * @since    Ver 1.1
 * @Date	 2011-6-8		下午11:09:21
 * 
 * @see 	 
 * @ deprecated 
 */
public class WebService {

	public String salyHeelo(String msg){
		return msg + "lewking";
	}
	
}

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
   <servlet>
   <display-name>Apache-Axis-Servlet</display-name>	
   <servlet-name>AxisServlet</servlet-name>
   <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
  </servlet>
   <servlet>
     <display-name>Axis Admin Servlet</display-name> 
     <servlet-name>AdminServlet</servlet-name>
     <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
     <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>
  <listener>
    <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
  </listener>
  
  
  <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>
  
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

server-config.wsdd
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
 xmlns="http://xml.apache.org/axis/wsdd/" xmlns:ns1="CmsServer">
<handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>

<service name="helloWord" provider="java:RPC">
  <parameter name="allowedMethods" value="*"/>
  <parameter name="className" value="com.lewking.web.WebService"/>
</service>
<!-- 可以配置多个 servie 节点 -->

<transport name="http">
	<requestFlow><handler type="URLMapper"/></requestFlow>
</transport></deployment>

Test Code
/**
 * WebServiceTest.java
 * com.lewking.test
 *
 * Function: TODO 
 *
 *   ver         date      	    author
 * ──────────────────────────────────────
 *  Ver 1.1	     2011-6-8 	    lewking
 *
 * Copyright (c) 2011, TNT All Rights Reserved.
*/

package com.lewking.test;


import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.junit.Test;

/**
 * ClassName:WebServiceTest
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   lewking
 * @version  
 * @since    Ver 1.1
 * @Date	 2011-6-8		下午11:24:34
 * 
 * @see 	 
 * @ deprecated 
 */
public class WebServiceTest {

	@Test
	public void test() throws ServiceException, RemoteException{
		String path ="http://localhost:8080/webservice/services/helloWord";
		Service service = new Service();
		Call call = (Call) service.createCall();
		
		call.setTargetEndpointAddress(path);
		call.setOperationName("salyHeelo");
		
		String msg =  (String) call.invoke(new Object[]{"hello"});
		System.out.println(msg);
		
	}
}

你可能感兴趣的:(java,apache,xml,webservice,servlet)