免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2354 | 回复: 0
打印 上一主题 下一主题

web service简单实例。myEclipse8.5。XFire [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-30 11:19 |只看该作者 |倒序浏览
web service简单实例。myEclipse8.5。XFire










一。服务器


XFire的
1创建web service project .会自动生成services.xml文件,用于配置。
方法随便写
如:
Java代码
  1. 1.package com.webservices;   
  2. 2.  
  3. 3.public class WebTwo {   
  4. 4.    public String webTwo_toOne(String message){   
  5. 5.        return(message);   
  6. 6.    }   
  7. 7.    public String webTwo_toTwo(String message){   
  8. 8.        return(message);   
  9. 9.    }   
  10. 10.    //里面可以定义很多方法。比如可以设置超时   
  11. 11.}  
  12. package com.webservices;

  13. public class WebTwo {
  14.         public String webTwo_toOne(String message){
  15.                 return(message);
  16.         }
  17.         public String webTwo_toTwo(String message){
  18.                 return(message);
  19.         }
  20.         //里面可以定义很多方法。比如可以设置超时
  21. }
复制代码
services.xml的代码
Java代码
  1. 1.<?xml version="1.0" encoding="UTF-8"?>   
  2. 2.<beans xmlns="http://xfire.codehaus.org/config/1.0">   
  3. 3. <service>   
  4. 4.        <name>webOne</name>   
  5. 5.        <serviceClass>com.webservices.WebOne</serviceClass>   
  6. 6.</service>   
  7. 7. <service>   
  8. 8.        <name>webTwo</name>   
  9. 9.        <serviceClass>com.webservices.WebTwo</serviceClass>   
  10. 10.</service>   
  11. 11.</beans>  
  12. <?xml version="1.0" encoding="UTF-8"?>
  13. <beans xmlns="http://xfire.codehaus.org/config/1.0">
  14. <service>
  15.         <name>webOne</name>
  16.         <serviceClass>com.webservices.WebOne</serviceClass>
  17. </service>
  18. <service>
  19.         <name>webTwo</name>
  20.         <serviceClass>com.webservices.WebTwo</serviceClass>
  21. </service>
  22. </beans>
复制代码
二。客户端。
1。创建一个 web service client 。地址是。工程名称/services/webOne
或者工程名称/services/webTwo 这个webOne和webTwo是services.xml里配置的名称,可以随便写。services是创建服务器端时的路径,默认是它,创建服务器端时,可自己随便写。。
2.
客户端代码
Java代码
  1. 1.  
  2. 2.public class webTwo {   
  3. 3.    public static void main(String[] args) {   
  4. 4.        webTwo_toOne();   
  5. 5.        webTwo_toTwo();   
  6. 6.    }   
  7. 7.    public static void webTwo_toOne(){   
  8. 8.        //生成的webTwoClient  和webTwoPortType 比较重要。   
  9. 9.// 在创建客户端时,就是web service client时,自己new几个包。   
  10. 10.//不要和服务器的包名相同,自然就会明白了....   
  11. 11.        webTwoClient  webc = new webTwoClient();   
  12. 12.           
  13. 13.        webTwoPortType webp = webc.getwebTwoHttpPort();   
  14. 14.           
  15. 15.        String s = webp.webTwo_toOne("webTwo Method One!");   
  16. 16.        System.out.println(s);   
  17. 17.    }   
  18. 18.    public static void webTwo_toTwo(){   
  19. 19.           
  20. 20.        webTwoClient  webc = new webTwoClient();   
  21. 21.           
  22. 22.        webTwoPortType webp = webc.getwebTwoHttpPort();   
  23. 23.           
  24. 24.        String s = webp.webTwo_toTwo("webTwo Method Two!");   
  25. 25.        System.out.println(s);   
  26. 26.    }   
  27. 27.  
  28. 28.}  
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP