helios创建Web Service服务

写好一个service服务后,点击右键,出现Web Service。。。如下图:



下面的步骤,除了启动server tomcat 服务外,其它都点击next就行了。


web hello service源代码:

package com.test.service;

public class HelloService {
	public String sayHelloNew() {
		return "hello";
	}

	public String sayHelloToPersonNew(String name) {
		if (name == null) {
			name = "nobody";
		}
		return "hello," + name;
	}

	public void updateData(String data) {
		System.out.println(data + " 已更新。");
	}
}

client:即调用web service的服务。

package com.test.client;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class CalculateClient {

	public void invokeHelloService() throws AxisFault {
		// 使用RPC方式调用WebService
		RPCServiceClient serviceClient = new RPCServiceClient();
		Options options = serviceClient.getOptions();
		// 指定调用WebService的URL
		EndpointReference targetEPR = new EndpointReference(
				"http://localhost:8080/CalculateService/services/HelloService");
		options.setTo(targetEPR);

		// 指定要调用的计算机器中的方法及WSDL文件的命名空间:edu.sjtu.webservice。
		QName opAddEntry = new QName("http://service.test.com",
				"sayHelloToPersonNew");// 加法
		// 指定plus方法的参数值为两个,分别是加数和被加数
		Object[] opAddEntryArgs = new Object[] { "CSDN" };
		// 指定plus方法返回值的数据类型的Class对象
		Class[] classes = new Class[] { String.class };
		// 调用plus方法并输出该方法的返回值
		System.out.println(serviceClient.invokeBlocking(opAddEntry,
				opAddEntryArgs, classes)[0]);
	}

	public void invokeCalculateService() throws AxisFault {
		// 使用RPC方式调用WebService
		RPCServiceClient serviceClient = new RPCServiceClient();
		Options options = serviceClient.getOptions();
		// 指定调用WebService的URL
		EndpointReference targetEPR = new EndpointReference(
				"http://localhost:8080/CalculateService/services/CalculateService");
		options.setTo(targetEPR);

		// 指定要调用的计算机器中的方法及WSDL文件的命名空间:edu.sjtu.webservice。
		QName opAddEntry = new QName("http://service.test.com", "plus");// 加法
		// 指定plus方法的参数值为两个,分别是加数和被加数
		Object[] opAddEntryArgs = new Object[] { 1, 5 };
		// 指定plus方法返回值的数据类型的Class对象
		Class[] classes = new Class[] { Float.class };
		// 调用plus方法并输出该方法的返回值
		System.out.println(serviceClient.invokeBlocking(opAddEntry,
				opAddEntryArgs, classes)[0]);
	}

	public static void main(String args[]) throws AxisFault {
		CalculateClient client = new CalculateClient();
		client.invokeCalculateService();
		client.invokeHelloService();
	}
}

2013-11-15 15:24:50 org.apache.axis2.deployment.ModuleDeployer deploy
信息: Deploying module: addressing-1.6.2 - file:/E:/repository/org/apache/axis2/axis2/1.6.2/axis2-1.6.2.jar
6.0
2013-11-15 15:24:51 org.apache.axis2.deployment.ModuleDeployer deploy
信息: Deploying module: addressing-1.6.2 - file:/E:/repository/org/apache/axis2/axis2/1.6.2/axis2-1.6.2.jar
hello,CSDN

 参考资料:

http://blog.csdn.net/xw13106209/article/details/7049614


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lzj0470

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值