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