XFire为访问服务端Web Service的方式

来源:互联网 发布:淘宝咸鱼不能搜索吗 编辑:程序博客网 时间:2024/05/22 18:12

XFire为访问服务端Web Service提供了各种方便的方式:

在可以获取服务端窄接口类的情况下,可以根据服务地址和窄接口类创建客户调用程序。

1.使用服务端的窄接口类

①根据窄接口创建Service模型

Service serviceModel = new ObjectServiceFactory().create(BbtForumService.class);

②服务对应URL地址

String serviceURL = "http://localhost:8080/baobaotao/service/BbtForumService";

BbtForumService service = null;

try {  ③将Web Service转换为窄接口实例

    service = (BbtForumService) new XFireProxyFactory().create(serviceModel, serviceURL);

} catch (Exception e) {

    throw new RuntimeException(e);

}

return service.getRefinedTopicCount(20);④调用Web Service方法


2. 使用WSDL文件构造客户端程序

try {

   String wsdl = "com/baobaotao/xfire/client/BbtForumService.wsdl";①对应的WSDL文件

   Resource resource = new ClassPathResource(wsdl);

   Client client = new Client(resource.getInputStream(), null);②根据WSDL创建客户实例

   ③调用特定的Web Service方法

   Object[] results = client.invoke("getRefinedTopicCount",new Object[]);

   return (Integer) results[0];

} catch (Exception e) {

   throw new RuntimeException(e);

}

XFire为访问服务端Web Service提供了各种方便的方式:
在可以获取服务端窄接口类的情况下,可以根据服务地址和窄接口类创建客户调用程序。
1.使用服务端的窄接口类
①根据窄接口创建Service模型
Service serviceModel = new ObjectServiceFactory().create(BbtForumService.class);
②服务对应URL地址
String serviceURL = "http://localhost:8080/baobaotao/service/BbtForumService";
BbtForumService service = null;
try {  ③将Web Service转换为窄接口实例
    service = (BbtForumService) new XFireProxyFactory().create(serviceModel, serviceURL);
} catch (Exception e) {
    throw new RuntimeException(e);
}
return service.getRefinedTopicCount(20);④调用Web Service方法

2. 使用WSDL文件构造客户端程序
try {
   String wsdl = "com/baobaotao/xfire/client/BbtForumService.wsdl";①对应的WSDL文件
   Resource resource = new ClassPathResource(wsdl);
   Client client = new Client(resource.getInputStream(), null);②根据WSDL创建客户实例
   ③调用特定的Web Service方法
   Object[] results = client.invoke("getRefinedTopicCount",new Object[]);
   return (Integer) results[0];
} catch (Exception e) {
   throw new RuntimeException(e);
原创粉丝点击