web Service
xml數(shù)據(jù)格式
SOAP(簡單對象訪問)
WSDL
-----------
開發(fā)步驟
1 建立服務(wù)并發(fā)布
XFire
× 導(dǎo)入jar包
* service.xml
* web.xml
創(chuàng)建接口
public interface IProcessCredit{
public String sayHello(String username);
}
和實現(xiàn)類
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調(diào)用服務(wù)
1 導(dǎo)入Service的jar
2 導(dǎo)入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 實現(xiàn)接口
public class ProessBookService implements IBookService {
public int addBook(Book book) {
BookDao bookDao=new BookDao();
return bookDao.addBook(book);
}
}
3 在src下創(chuàng)建META-INF文件夾,在META-INF下創(chuàng)建xfire文件夾,在xfire下創(chuàng)建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 編寫調(diào)用方法
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 閱讀(297)
評論(0) 編輯 收藏 所屬分類:
jsp/servlet