webservice客户端调用常用的两种方法

来源:互联网 发布:三案始末 知乎 编辑:程序博客网 时间:2024/05/22 05:20

xfire代理调用:

public static void main(String[] args) {//创建服务的元数据Service serviceModel=new ObjectServiceFactory().create(Ihello.class);//创建服务代理XFire xfire=XFireFactory.newInstance().getXFire();XFireProxyFactory factory = new XFireProxyFactory(xfire);//服务地址String serviceUrl="http://localhost:8088/service/services/hello";//服务代理通过服务元数据和服务地址取得服务实例try {Ihello helloService=(Ihello)factory.create(serviceModel, serviceUrl);String helloResponse=helloService.sayHello("张三");//-1,0,1<System.out.println("服务器返回的结果是:"+helloResponse);} catch (MalformedURLException e) {e.printStackTrace();}}


 

RPC远程过程调用:

public static void main(String[] args) {//创建服务的元数据Service serviceModel=new ObjectServiceFactory().create(Ihello.class);//创建服务代理XFire xfire=XFireFactory.newInstance().getXFire();XFireProxyFactory factory = new XFireProxyFactory(xfire);//服务地址String serviceUrl="http://localhost:8088/service/services/hello";//服务代理通过服务元数据和服务地址取得服务实例try {Ihello helloService=(Ihello)factory.create(serviceModel, serviceUrl);String helloResponse=helloService.sayHello("张三");//-1,0,1<System.out.println("服务器返回的结果是:"+helloResponse);} catch (MalformedURLException e) {e.printStackTrace();}}


 

原创粉丝点击