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 閱讀(293)
評論(0) 編輯 收藏 所屬分類:
jsp/servlet