http://blog.csdn.net/ljah/archive/2007/08/30/1765099.aspx
一、 声明
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</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>
|
public class myService {
public String getusername(String name){
return "Hello "+name+",this is an Axis DII Web Service";
}
}
|
public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException {
String endpoint="http://localhost:8080/AxisTest/myService.jws";
String name="
邹萍
";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.addParameter("param1",XMLType.XSD_STRING,ParameterMode.IN);
call.setOperationName( "getusername" );
call.setReturnType( XMLType.XSD_STRING );
String ret = (String) call.invoke( new Object[] { name } );
System.out.println("
返回结果:
" + ret);
}
|
package com.service;
public class myService {
public String getusername(String name){
return "Hello "+name+",this is an Axis Web Service";
}
}
|
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>
<service name="myService" provider="java:RPC">
<parameter name="className" value="com.service.myService"/>
<parameter name="allowedMethods" value="getusername"/>
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper"/>
</requestFlow>
</transport>
</deployment>
|
package com.axistest;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class myServiceTestorByWSDD {
public tatic void main(String[] args) throws ServiceException,MalformedURLException, RemoteException {
String endpoint = "http://localhost:8080/AxisTest/services/myService";
Service service = new Service(); //
创建一个
Service
实例,注意是必须的!
Call call = (Call) service.createCall(); //
创建
Call
实例,也是必须的!
call.setTargetEndpointAddress(new java.net.URL(endpoint));//
为
Call
设置服务的位置
call.setOperationName("getusername"); //
注意方法名与
JavaBeanWS.java
中一样!!
String res = (String) call.invoke(new Object[] { "
邹萍
" }); //
返回
String
,传入参数
System.out.println(res);
}
}
|
<?xml version="1.0" encoding="UTF-8"?>
<project name="Generate WSDL from JavaBeans as Web Services" default="j2w-all" basedir=".">
<property name="build.dir" value="../WEB-INF/classes"/>
<property name="axis.dir" location="D:/Java/axis-1_4"/>
<path id="classpath.id">
<fileset dir="${axis.dir}/lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${build.dir}"/>
</path>
<taskdef name="axis-java2wsdl" classname="org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask"
loaderref="axis" >
<classpath refid="classpath.id"/>
</taskdef>
<target name="j2w-all">
<antcall target="j2w-JavaBeanWS"/>
</target>
<target name="j2w-JavaBeanWS">
<axis-java2wsdl classname="com.service.myService" classpath="${build.dir}"
methods="getusername"
output="myService.wsdl"
location="http://localhost:8080/AxisTest/services/myService"
namespace="http://localhost:8080/AxisTest/services/myService"
namespaceImpl="http://localhost:8080/AxisTest/services/myService">
</axis-java2wsdl>
</target>
</project>
|
<?xml version="1.0" encoding="UTF-8"?>
<project name="wsclient" default="all" basedir=".">
<property name="axis.home" location="D:\Java\axis-1_4"/>
<property name="options.output" location="../wsdl2java"/>
<path id="axis.classpath">
<fileset dir="${axis.home}/lib">
<include name="**/*.jar"/>
</fileset>
</path>
<taskdef resource="axis-tasks.properties" classpathref="axis.classpath" />
<target name="-WSDL2Axis" depends="init">
<mkdir dir="${options.output}"/>
<axis-wsdl2java output="${options.output}" url="${options.WSDL-URI}" verbose="true"/>
</target>
<target name="init">
<echo>Warning: please update the associated WSDL file(s) in the folder wsdl before running the target!</echo>
<echo>Warning: Just run the target(s) related with your developing work!</echo>
<echo></echo>
</target>
<target name="all">
<antcall target="myService"/>
</target>
<target name="myService">
<antcall target="-WSDL2Axis">
<param name="options.WSDL-URI" location="../java2wsdl/myService.wsdl"/>
</antcall>
</target>
</project>
|
package com.axistest;
import localhost.AxisTest.services.myService.MyService;
import localhost.AxisTest.services.myService.MyServiceServiceLocator;
public class myServiceTestorByStubs {
public static void main(String[] args) throws Exception
{
MyServiceServiceLocator Service= new MyServiceServiceLocator();
MyService port= Service.getmyService();
String response=port.getusername("
邹萍
");
System.out.println(response);
}
}
|
发表于 @ 2007年08月30日 11:13:00|评论(0 )|编辑