1)服务器端开发
说明:jdk为1.7版本
i.创建项目
项目名称:webs1
ii.创建SEI(终端)
a.包名:cn.jbit.webs1.sei
b.接口设计
接口名:HelloSEI.java
接口内容:
@WebService
public interface HelloSEI {
@WebMethod
public String sayHello(String name);
}
c.实现类设计
实现类名:HelloSEIImpl.java
实现类内容:
@WebService
public class HelloSEIImpl implements HelloSEI {
@Override
public String sayHello(String name) {
System.out.println("sayhello");
return "hello"+name;
}
}
iii.发布服务
a.包名:cn.jbit.webs1.sei.test
b.发布
类名:HelloSEITest.java
类内容:
public class HelloSEITest {
public static void main(String[] args) {
String address = "http://192.168.8.116:8989/webs1/hello";
Endpoint.publish(address, new HelloSEIImpl());
System.out.println("发布");
}
}
2)客户端开发
i.创建项目
项目名称:wsclient
ii.使用jdk提供的wsimport.exe生成客户端代码
wsimport -target 2.0 -keep http://192.168.8.116:8989/webs1/hello?wsdl
iii.调用服务
a.包名:cn.jbit.webs1.sei.client
b.调用
类名:ClientTest.java
类内容:
public class ClientTest {
public static void main(String[] args) {
HelloSEIImplService helloSEIImplService = new HelloSEIImplService();
HelloSEIImpl helloSEIImpl = helloSEIImplService.getHelloSEIImplPort();
String result = helloSEIImpl.sayHello("xiaoxiao");
System.out.println(result);
}
}
使用jdk 创建web service
原创
©著作权归作者所有:来自51CTO博客作者素颜猪的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:struts-上传
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
当创建一个service后,kubernetes会发生什么?
Kubernetes为什么会引入service?
Pod Endpoint IP service clusterIP -
使用Dockerfile创建jdk镜像
使用Dockerfile创建jdk镜像。
java docker linux JAVA 环境变量