基于 xfire 的 webservice 项目

基于 xfire 的 webservice 项目
   如果想入门的自己看看吧!

项目机构图:
项目机构图

客户端的两种调用方式:

package com.xfire.client;


import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import com.xfire.hello.IHelloWorld;

/**
 * 类说明
 * @author  yuan_liang
 * @email   [email protected]
 * @version V1.0  创建时间:May 28, 2010 5:42:01 PM
 * 类作用描述:
 */
public class HelloWSClient {
   
 public static void main(String[] args) {

  
  
     HelloWSClient wsc = new HelloWSClient();
     wsc.client1();
    
 }
 
 public void client1(){
    
     String wsdlUrl = "http://192.168.1.73:8080/xfire/services/HelloWorld?wsdl";
    
     try{
      URL url = new URL(wsdlUrl);
      HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
      httpConnection.connect();
      Client client = new Client(httpConnection.getInputStream(),null);  
      Object []results = client.invoke("example", new Object[]{"hello"});
     
      //return (String)results[0];
     }catch(Exception e){
      throw new RuntimeException(e);
     }
  
 }

 public void client2(){
  
     Service service = new ObjectServiceFactory().create(IHelloWorld.class);
     XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
    
     String helloWordURL="http://localhost:8080/xfire/services/HelloWorld";
    
     IHelloWorld srvc = null;
     try {
      srvc = (IHelloWorld) factory.create(service,helloWordURL);
     
      String result = srvc.example("Hello---wode love1");
     
      System.out.println(result);
     } catch (MalformedURLException e) {
    e.printStackTrace();
     }
  
 }

}

---------说明:项目是我自己搭建的服务器端和客户端的都用,如有需要请下载--------------------

猜你喜欢

转载自blog.csdn.net/joynet007/article/details/83635744