前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用JDK开发web service

用JDK开发web service

作者头像
汤高
发布2018-01-11 17:26:45
5930
发布2018-01-11 17:26:45
举报
文章被收录于专栏:积累沉淀积累沉淀

服务器端     编码:         a. 创建一个基于jdk6以上版本的java工程         b. 定义SEI web service Endpoint interface(web service终端接口)             @WebService             public interface HelloWS {                 @WebMethod                 public String sayHello(String name);             }         c. 定义SEI的实现类:             @WebService             public class HelloWSImpl implements HelloWS {                 @Override                 public String sayHello(String name) {                     System.out.println("sayHello "+name);                     return "hello "+name;                 }             }     发布:         public class Server {             public static void main(String[] args) {                 //客户端发送web service请求的url                String address="http://127.0.0.1/tg_ws/helloWS";                 //处理请求的SEI对象                 HelloWS helloWS = new HelloWSImpl();                 //发布web service                 Endpoint.publish(address, helloWS);                 System.out.println("发布web service成功!");             }         }

   (注:我的要建一个ServerDelegate  在Server基础上点击 打开new=》other=》输入 web service 点击=》选择 create web service from java class=》打开Brouwse 输入你的测试类 最后勾上 Generate WSDL in project   会生成一个 * Delegate.java)

②. 客户端     1. eclipse Web Service浏览器         a. 查看Web Service所对应的WSDL文档:...?wsdl         b. 使用eclipse访问             请求体:SOAP Request Envelope                 <soapenv:Envelope>                     <soapenv:Body>                         <q0:sayHello>                             <arg0>tt</arg0>                         </q0:sayHello>                     </soapenv:Body>                 </soapenv:Envelope>             响应体:SOAP Response Envelope                 <S:Envelope>                     <S:Body>                         <ns2:sayHelloResponse xmlns:ns2="http://ws.java.atguigu.net/">                             <return>hello tt</return>                         </ns2:sayHelloResponse>                     </S:Body>                  </S:Envelope>

    2. 编码实现         a. 创建客户端java应用         b. 在应用的src下执行cxf的命令生成客户端代码:             wsimport -keep http://127.0.0.1/tg_ws/helloWS?wsdl         c. 编写客户端调用的测试代码,执行:             public class Client {                 public static void main(String[] args) {                     //创建SEI的工厂对象                     HelloWSImplService factory = new HelloWSImplService();                     //得到一个SEI实现类对象                     HelloWSImpl helloWS = factory.getHelloWSImplPort();                     //调用SEI的方法,此时才去发送web Service请求,并得到返回结果                     String result = helloWS.sayHello("Tom");                     System.out.println(result);                 }             }         ③.请求过程记录:使用eclipse的tcp/ip工具进行请求的监控

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档