WebService入门
2016-03-08 16:07
218 查看
1. 新建JavaWeb Project。
2. 新建远程调用的接口,HelloWorld.java,源码如下
3. 实现远程调用接口,HelloWorldImp.java,源码如下:(注意webService注解)
4. 编写启动服务程序,HelloWorldTest.java,代码如下:
运行HelloWorldTest.java程序。浏览器访问http://192.168.19.188:8080/helloWorld?wsdl,效果如下图所示:
至此,服务器端开发完成。
客户端开发过程如下:
1. 新建客户端JAVA Web 开发工程WebClient。
2. 进入工程WebClient的src路径下,执行命令:wsimport -keep url(url为wsdl文件的路径)生成客户端代码。如下图所示:
3. 进入eclipse的WebClient工程,刷新目录,自动生成的代码,出现,如下图所示:
4. 编写客户端程序HelloWorldTest.java,源码如下所示:
运行效果如下图所示:
源码下载:https://yunpan.cn/cYm5wVevNsH4B (提取码:53f0)
参考网址:http://www.cnblogs.com/xdp-gacl/p/4259481.html
2. 新建远程调用的接口,HelloWorld.java,源码如下
package com.cvicse.ump.webservices.hello; public interface HelloWorld { public String sayHello(String name); public String getHelloName(); }
3. 实现远程调用接口,HelloWorldImp.java,源码如下:(注意webService注解)
package com.cvicse.ump.webservices.hello.imp; import javax.jws.WebService; import com.cvicse.ump.webservices.hello.HelloWorld; @WebService public class HelloWorldImp implements HelloWorld{ @Override public String sayHello(String name) { return "hello,"+name; } @Override public String getHelloName() { return "World"; } }
4. 编写启动服务程序,HelloWorldTest.java,代码如下:
package com.cvicse.ump.webservices.hello; import javax.xml.ws.Endpoint; import com.cvicse.ump.webservices.hello.imp.HelloWorldImp; public class HelloWorldTest { public static void main(String[] args) { HelloWorld helloWorld = new HelloWorldImp(); String url = "http://192.168.19.188:8080/helloWorld"; Endpoint.publish(url, helloWorld); System.out.println("Web Services start..."); } }
运行HelloWorldTest.java程序。浏览器访问http://192.168.19.188:8080/helloWorld?wsdl,效果如下图所示:
至此,服务器端开发完成。
客户端开发过程如下:
1. 新建客户端JAVA Web 开发工程WebClient。
2. 进入工程WebClient的src路径下,执行命令:wsimport -keep url(url为wsdl文件的路径)生成客户端代码。如下图所示:
3. 进入eclipse的WebClient工程,刷新目录,自动生成的代码,出现,如下图所示:
4. 编写客户端程序HelloWorldTest.java,源码如下所示:
package com.cvicse.ump.webservices.hello; import com.cvicse.ump.webservices.hello.imp.HelloWorldImp; import com.cvicse.ump.webservices.hello.imp.HelloWorldImpService; public class HelloWorldTest { public static void main(String[] args) { HelloWorldImpService helloWorldImpService = new HelloWorldImpService(); HelloWorldImp helloWorldImp = helloWorldImpService.getHelloWorldImpPort(); String result = helloWorldImp.sayHello("dyh"); String helloName = helloWorldImp.getHelloName(); System.out.println(result); System.out.println(helloName); } }
运行效果如下图所示:
源码下载:https://yunpan.cn/cYm5wVevNsH4B (提取码:53f0)
参考网址:http://www.cnblogs.com/xdp-gacl/p/4259481.html
相关文章推荐
- Maven多模块项目依赖管理
- HeadFirst设计模式之观察者模式
- 使用while循环语句和变量输出九九乘法表
- ios键盘高度监听
- iOS 强引用(__strong)和弱引用(__weak)浅析
- s设置cookie的简单方法
- 双向链表的逆置(两种)
- Gradle 从入门到精通
- android屏幕自适应&&android 属性
- 检测手机类型、密度比和物理宽高
- 无参考图像的清晰度评价方法
- Gradle 从入门到精通
- React Native开发之按钮的使用
- 从网站解析JSON异步加载到ListView事例
- InnoDB引擎的auto_increment字段和MyISAM引擎的auto_increment字段的异同
- HashMap原理
- 编写界面的最佳实践——聊天界面
- 宏元编程——算数计算——ADD,SUB,MUL
- 带按钮的listview
- Eclipse+ADT+Android SDK 搭建安卓开发环境