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>
<?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>
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;}}