Axis 即使发布 JWS

1.服务端代码
/**
 * 注意:JWS不支持带包的类 
 * @author Administrator
 */
public class JWSTest {

	public String Say(String name) {
		if (null == name)
			return "Administrator Hello";
		else
			return name + " Hello";
	}
}


2. 将改java类(例 JWSTest.java文件)拷贝至Axis的根目录下并将改文件后缀名改成(JWTest.jws)
3. 然后访问 http://ip:port/axis/JWTest.jws 如图所示
Axis 即使发布 JWS_第1张图片

4.单击 Click to see the WSDL

Axis 即使发布 JWS_第2张图片

5.接下来就是编写客户端了

import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class Client {
	public static void main(String[] args){
		
		String url = "http://localhost:9090/axis/JWSTest.jws";
		Service service = new Service();
		try {
			Call call = (Call) service.createCall();
			
			call.setTargetEndpointAddress(url);
			
			call.setOperationName(new QName(url,"Say"));
			
			String result = (String)call.invoke(new Object[]{"yuanyong javeye"});
			
			System.out.println(result);
			
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
	}
	
}




6.运行结果




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