当前位置: 代码迷 >> Web前端 >> axis公布webservices
  详细解决方案

axis公布webservices

热度:55   发布时间:2012-09-29 10:30:01.0
axis发布webservices
axis发布webservices


1 下载axis包。
2 将包解压,将其中webapp下面的axis文件夹copy到tomcat的webapps下面。
3 访问http://localhost:8080/axis/成功显示
4 新建测试项目web_test,将axis包解压出来的lib下面的包添加进去。
5 编写webservice服务类

public class Sum {
	public String AddString(String name, String pass) {
		return name + pass;
	}

}

6 将Sum.java修改为Sum.jws放到apache-tomcat-6.0.26\webapps\axis下面
7 http://localhost:8080/axis/Sum.jws?wsdl
8 建立测试类
  在测试项目web_test中建

package com;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

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


public class SayHelloClient2 {

	public static void getAddString()
	{
		try {
			String endpoint = "http://localhost:8080/axis/Sum.jws";
			Service service = new Service();
			Call call = null;
			call = (Call) service.createCall();
			call.setOperationName(new QName(
					endpoint, "AddString"));
			call.setTargetEndpointAddress(new java.net.URL(endpoint));
/*参数*/
			String ret = (String) call.invoke(new Object[] { "你好啊:","king" });
			System.out.println("return value is " + ret);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	
	public static void main(String[] args) {
		getAddString();
	}

	
}


?