webService学习记录

服务端配置
1、新建web项目,导入xFire的jar包
2、创建服务接口、实现类
3、创建src->META-INF->service->service.xml
将实现类、接口配置到里面
配置接口namespace
4、在web.xml中配置servlet、servlet-mapping(xFire)
5、部署项目,通过浏览器访问 localhost:8080/[testXfire]/[service]

客户端
1、新建web项目,将服务端代码打成jar包导入项目
同时导入xFire的包
2、见链接类
package com.gdie.xfire.test;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import com.gdie.xfire.example.ITestService;
public class MyClient {
public static void main(String[] args) {
try{
Service serviceModel = new ObjectServiceFactory().create(
ITestService.class,"TestService","http://com/gdie/xfire/example/ITestService",null);
ITestService service = (ITestService) new XFireProxyFactory().create(
serviceModel,"http://localhost:8080/TestXFile/services/TestService");
System.out.println("返回值是:"+service.add(5, 8));
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}

posted @ 2014-04-08 10:24  tancp  阅读(116)  评论(0编辑  收藏  举报