webservice客户端调用常用的两种方法
发布时间:2020-12-17 00:01:26 所属栏目:安全 来源:网络整理
导读:xfire代理调用: public static void main(String[] args) {//创建服务的元数据Service serviceModel=new ObjectServiceFactory().create(Ihello.class);//创建服务代理XFire xfire=XFireFactory.newInstance().getXFire();XFireProxyFactory factory = new
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,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,1< System.out.println("服务器返回的结果是:"+helloResponse); } catch (MalformedURLException e) { e.printStackTrace(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |