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();
}
}
本文展示了如何使用 XFire 实现 RPC 远程过程调用,通过创建服务元数据、服务代理并指定服务地址来获取服务实例,最终完成远程调用并展示服务器返回结果。
622

被折叠的 条评论
为什么被折叠?



