首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

webService 之 xFire 兑现流程

2012-08-28 
webService 之 xFire 实现流程1.用eclipse新建一个webservice项目工程2.WebRoot/WEB-INF/web.xml里面的内

webService 之 xFire 实现流程
1.用eclipse新建一个webservice项目工程
2.WebRoot/WEB-INF/web.xml里面的内容

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  <servlet>    <servlet-name>XFireServlet</servlet-name>    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>    <load-on-startup>0</load-on-startup>  </servlet>  <servlet-mapping>    <servlet-name>XFireServlet</servlet-name>    <url-pattern>/services/*</url-pattern>  </servlet-mapping>  <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list></web-app>

3.WebRoot/WEB-INF/META-INF/xfire/services.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://xfire.codehaus.org/config/1.0">  <service>  <name>CertAuthenticateService</name>  <namespace>http://service.com</namespace>  <serviceClass>com.service.ICertAuthenticateService</serviceClass>  <implementationClass>com.service.CertAuthenticateServiceImpl</implementationClass>  </service></beans> 

4.服务端程序:一个接口,一个实现接口的类
5.
客户端代码一:
package com.client;import java.net.MalformedURLException;import org.codehaus.xfire.XFire;import org.codehaus.xfire.XFireFactory;import org.codehaus.xfire.client.XFireProxyFactory;import org.codehaus.xfire.service.Service;import org.codehaus.xfire.service.binding.ObjectServiceFactory;import com.service.CertAuthenticateServiceImpl;import com.service.ICertAuthenticateService;public class Client {public static void main(String[] args) {String serviceURL = "http://localhost:8080/webservice_03/services/CertAuthenticateService?wsdls";Class clazz = ICertAuthenticateService.class;ICertAuthenticateService iCertAuthenticateService = (ICertAuthenticateService)Client.getObj(clazz, serviceURL);iCertAuthenticateService.queryAuthentcateResult("cert");}public static Object getObj(Class clazz, String serviceURL) {Service serviceModel = new ObjectServiceFactory().create(clazz);XFire xFire = XFireFactory.newInstance().getXFire();XFireProxyFactory factory = new XFireProxyFactory(xFire);Object service = null;try {service = factory.create(serviceModel, serviceURL);} catch (MalformedURLException e) {e.printStackTrace();}return service;}}

客户端代码二:
新建一个 webService 项目,再新建一个 webService Client ,URL 指向 wsdl 或者 指向一个 wsdl 文件,新建一个找到一个以 Client 结尾的类,类里面有 main 方法可以调用。

热点排行