微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webservice 客户端调用

现在我们来看xfire的客户端调用,有两种方式:

一、通过服务端提供的接口类进行调用

Java代码

复制代码

  1. package com.wujianjun.xfire.client;  
  2.   
  3. import java.net.MalformedURLException;  
  4. import java.util.List;  
  5.   
  6. import org.codehaus.xfire.XFire;  
  7. import org.codehaus.xfire.XFireFactory;  
  8. import org.codehaus.xfire.client.XFireProxyFactory;  
  9. import org.codehaus.xfire.service.Service;  
  10. import org.codehaus.xfire.service.binding.ObjectServiceFactory;  
  11.   
  12. import com.wujianjun.xfire.domain.Person;  
  13. import com.wujianjun.xfire.spring.IPersonService;  
  14.   
  15. public class PojoInvokeClient  
  16.   
  17.     public static void main(String[] args)  
  18.         Service serviceModel new ObjectServiceFactory().create(IPersonService.class);  
  19.   
  20.         XFire xfire XFireFactory.newInstance().getXFire();  
  21.         XFireProxyFactory factory new XFireProxyFactory(xfire);  
  22.         String serviceUrl "http://127.0.0.1:8080/xfire/services/PersonService" 
  23.   
  24.         IPersonService client null 
  25.         try  
  26.             client (IPersonService) factory.create(serviceModel, serviceUrl);  
  27.         catch (MalformedURLException e)  
  28.             System.out.println("Client call webservice has exception: "e.toString());  
  29.          
  30.   
  31.         String result1 =client.sayHello("张三");  
  32.           
  33.      

 二、直接通过url调用,不用客户端提供接口类

Java代码

复制代码

  1. package com.wujianjun.xfire.client;  
  2.   
  3. import java.net.MalformedURLException;  
  4. import java.net.URL;  
  5.   
  6. import org.codehaus.xfire.client.Client;  
  7.   
  8. public class UrlInvokeClient  
  9.   
  10.     public static void main(String[] args)  
  11.         Client client null 
  12.         try  
  13.             client new Client(new URL("http://127.0.0.1:8080/xfire/PersonService.ws?wsdl"));  
  14.             Object[] result1 client.invoke("sayHello"new Object[] {"张三"});  
  15.             System.out.println(result1[0]);  
  16.         catch (MalformedURLException e)  
  17.             e.printstacktrace();  
  18.         catch (Exception e)  
  19.             e.printstacktrace();  
  20.          
  21.      

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐