`

java_XFire_webservice

    博客分类:
  • Java
 
阅读更多

服务器端

新建XFire Webservice Project



 

 

新建service 接口 XfireService 以及其实现类 XfireServiceImpl.

package service.xfire;

public interface XfireService {

public String method1();

public String method2(String arg);

}

 

package service.xfire;

public class XfireServiceImpl implements XfireService {

public String method1() {

System.out.println("this is xfire method 1");

return null;

}

public String method2(String arg) {

System.out.println("this is xfire method 1 and the arg is "+arg);

return null;

}

}

 

配置 service.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://xfire.codehaus.org/config/1.0">

  <service>

    <name>XfireService</name>

    <namespace>http://com.service.xfire/XfireService</namespace>

    <serviceClass>service.xfire.XfireService</serviceClass>

    <implementationClass>service.xfire.XfireServiceImpl</implementationClass>

  </service>

</beans> 
 服务器端开发完成,最终目录结构如下图



 在tomcat下部署后,用 Web Services Explorer 查看WSDL。



如下图则服务器端成功 



也可在浏览器查看



 

 客户端

新建一个java project.并添加xfire客户端jar(会同时导入服务器端jar)

 

 

 

  

新建一个test类,并新建一个和服务器端一样的接口interface。

package client.xfire;

import java.net.MalformedURLException;

import org.codehaus.xfire.XFireFactory;

import org.codehaus.xfire.client.XFireProxyFactory;

import org.codehaus.xfire.service.Service;

import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class XfireTest {

public static void main(String[] args) {

Service service = new ObjectServiceFactory().create(XfireService.class);

XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());

String svcURL = "http://localhost:8080/xfireService/services/XfireService";

try {

XfireService srvc = (XfireService)factory.create(service, svcURL);

srvc.method1();

srvc.method2("hahaha :)");

} catch (MalformedURLException e) {

e.printStackTrace();

}

}

}

 

客户端目录如下


 运行test类 ,结果如下,客户端成功  



  • 大小: 50.5 KB
  • 大小: 57.6 KB
  • 大小: 53.8 KB
  • 大小: 21.3 KB
  • 大小: 46.2 KB
  • 大小: 91.8 KB
  • 大小: 153.3 KB
  • 大小: 47.4 KB
  • 大小: 40.5 KB
  • 大小: 51.3 KB
  • 大小: 13.2 KB
  • 大小: 18.1 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics