利用XFire创建Web服务

 <!--利用XFire创建Web服务-->

//配制services.xml

<service>
 <name>XXXService</name>
 <serviceClass>implementAddr</serviceClass>
 <implementationClass>implAddr</implementationClass>
 <style>wrapped</style>
 <use>literal</use>
 <scope>application</scope>
</service> 

1.创建服务接口模板

Service serviceModel=new ObjectServiceFactory().create(XXXService.class);

 2.创建工厂代理

 XFireProxyFactory factory=new XFireProxyFactory(XFireFactory.newInstance().getXFire());

3.定义Web服务地址
  String accountServiceURL="http://localhost:port/project name/services/XXXService";

4.根据接口模板和Web服务地址返回服务类

XXXService service=(XXXService) factory.create(serviceModel,accountServiceURL);

5.调用Web服务接口方法

service.getMethed(params);

 

 

 

 

 

 

 --备忘录

//创建服务接口模板
  Service serviceModel=new ObjectServiceFactory().create(AddNumService.class);
  
  //创建工厂代理
  XFireProxyFactory factory=new XFireProxyFactory(XFireFactory.newInstance().getXFire());
  
  //定义Web服务地址
  String accountServiceURL="http://userswo-d3s6dnu:8080/Spring06/services/addSumService";
  
  try {
   //根据接口模板和Web服务地址返回服务类
   AddNumService add=(AddNumService) factory.create(serviceModel,accountServiceURL);
   //根据参数调用方法,并返回结果
   Scanner input=new Scanner(System.in);
   System.out.print("请输入一个任意整数:");
   int input_num=input.nextInt();
   int result=add.Sum(input_num);
   
   System.out.println("1到"+input_num+"的和为:"+result);
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

 

 

posted @ 2013-02-25 19:59  果然翁  阅读(354)  评论(0)    收藏  举报