web Service
xml数据格式
SOAP(简单对象访问)
WSDL
-----------
开发步骤
1 建立服务并发布
XFire
× 导入jar包
* service.xml
* web.xml
创建接口
public interface IProcessCredit{
public String sayHello(String username);
}
和实现类
public class ProcessCreditImpt implement IProcessCredit{
public String sayHello(String username){
return "你好"+username;
}
}
编写配置文件
services.xml
<service>
<name>CreditCard</name>
<namespace>http://www.CreditCard.com</namespace>
<serviceClass>
org.com.IProcessCredit
</serviceClass>
<implementationClass>
org.com.ProcessCreditImpt
</implementationClass>
2 客户端servlet调用服务
1 导入Service的jar
2 导入XFire的jar
3 Service
Service service=new ObjectServiceFactory().create(IProcessCredit.class);
XFire xfire=XfireFactory.newInstance().getXFire();
XFireProxyFactory factory=new XFireProxyFactory(xfire);
String url="";
IProcessCredit c=(IProcessCredit)factor.create(service,url);
c.sayHello("ddddddddddd");
-----------------------------------------------------------------
步骤:
1 建立接口
public interface IBookService {
public int addBook(Book book);
}
2 实现接口
public class ProessBookService implements IBookService {
public int addBook(Book book) {
BookDao bookDao=new BookDao();
return bookDao.addBook(book);
}
}
3 在src下创建META-INF文件夹,在META-INF下创建xfire文件夹,在xfire下创建services.xml
(src-->META-INF-->xfire-->services.xml)
<service>
<name>BookService</name>
<namespace>http://www.book.com</namespace>
<serviceClass>org.book.IBookService </serviceClass>
<implementationClass>org.book.ProessBookService </implementationClass>
</service>
4 编写web.xml
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
5 编写调用方法
Service serviceModle=new ObjectServiceFactory().create(IBookService.class);
XFire xFire=XFireFactory.newInstance().getXFire();
XFireProxyFactory factory=new XFireProxyFactory(xFire);
String urlString="http://localhost:8080/ownhome/services/ProessBookService";
IBookService bookService=(IBookService) factory.create(serviceModle, urlString);
posted on 2009-11-29 22:48
junly 阅读(287)
评论(0) 编辑 收藏 所属分类:
jsp/servlet