2024年5月29日发(作者:)
第一个的webservice实例
超简单,才5步
1> 获取axis及关联的jar包
/topics/download/6a76de1e-d506-35bc-a41b-508d4be04025
2> 新建一个模拟服务java类
package server;
public class SayHello {
public String getName(String name) {
return "你好," + name;
}
}
3> 在 下新增一个servelt
4> 在web项目的 同目录新建文件 ,自己改改
xmlns:java="/axis/wsdd/providers/java"> value="mentsImpl"/>
5> 运行tomcat ,如果输入:localhost:8080/项目名/services 如下显示:
说明webservice部署成功。
6> 随便写个客户端,调用吧
package client;
import ;
import e;
public class TestClient {
public static void main(String[] args) throws Exception {
// 指出service所在URL
String endpoint = "localhost:8080/services/";
// 创建一个服务(service)调用(call)
Service service = new Service();
Call call = (Call) Call();// 通过service创建call对象
// 设置service所在URL
getEndpointAddress(new (endpoint));
// 方法名(processService)与方法名保持一致
rationName("getName");
// Object 数组封装了参数,参数为"This is Test!",调用processService(String arg)
String ret = (String) (new Object[] { "帅哥!" });
n(ret);
}
}
输出结果如下:
作者QQ: 339751607 , 希望各位读者帮我踩踩空间哈,谢谢哈^_*
/339751607


发布评论