axis生成webservices的客户端代码

先下载axis jar包:axis-bin-1_4.zip。下载地址: http://ws.Apache.org/axis/。 

1、 配置到classpath

将axis.jar配置到classpath下



 



 

2、创建一个bat文件内容为 :

set Axis_Lib=E:\sf-work\JAR\ws\axis-1_4\lib

set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%

set Output_Path=E:\sf-work\JAR\ws\axis\test

set Package=com.axis.service.hw 

%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% http://localhost:8080/services/HelloWorld?wsdl

3、进入cmd执行bat

4、客户端调用

xxxLocator servince = new xxxLocator();
xxxSoap_PortType client = servince.getxxxSoap();
String xmlDoc = client.getxxxx("xxxx");//此处为ws提供的方法

 例子(根据上一篇Axis+Spring中的服务端例子生成客户端):

package com.axis.client.test;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.junit.Test;

import com.axis.service.hw.JaxRpcHelloWorld;
import com.axis.service.hw.JaxRpcHelloWorldServiceLocator;

public class ClientTest {

	@Test
	public void test() {
		try {
			JaxRpcHelloWorldServiceLocator service = new JaxRpcHelloWorldServiceLocator();
			JaxRpcHelloWorld jaxRpcHelloWorld;
			jaxRpcHelloWorld = service.getHelloWorld();
			String str = jaxRpcHelloWorld.getMessage("HelloWorld--WSDL2java");
			System.out.println(str);
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}
}

猜你喜欢

转载自tzz6.iteye.com/blog/2269229