webService 之 xFire 实现流程

阅读更多
1.用eclipse新建一个webservice项目工程
2.WebRoot/WEB-INF/web.xml里面的内容


  
    XFireServlet
    org.codehaus.xfire.transport.http.XFireConfigurableServlet
    0
  
  
    XFireServlet
    /services/*
  
  
    index.jsp
  


3.WebRoot/WEB-INF/META-INF/xfire/services.xml

  
	  
		CertAuthenticateService  
		http://service.com  
		com.service.ICertAuthenticateService  
		com.service.CertAuthenticateServiceImpl  
	
 

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 方法可以调用。
  • webService_xFire资料.rar (1.3 MB)
  • 下载次数: 11
  • 开发XFire_Web_Service应用.pdf (1.2 MB)
  • 下载次数: 8

你可能感兴趣的:(java,webservice,web)