加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice 客户端调用

发布时间:2020-12-17 00:27:07 所属栏目:安全 来源:网络整理
导读:现在我们来看xfire的客户端调用,有两种方式: 一、通过服务端提供的接口类进行调用。 Java代码 package ? com.wujianjun.xfire.client;? ? ? ? import ? java.net.MalformedURLException;? ? import ? java.util.List;? ? ? ? import ? org.codehaus.xfire.X

现在我们来看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. ????}??
  34. }?

?二、直接通过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. ????}??
  22. }?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读