webservice xfire 客户端调用

现在我们来看xfire的客户端调用,有两种方式:

一、通过服务端提供的接口类进行调用。

Java代码 
package com.wujianjun.xfire.client;    
   
import java.net.MalformedURLException;    
import java.util.List;    
   
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.wujianjun.xfire.domain.Person;    
import com.wujianjun.xfire.spring.IPersonService;    
   
public class PojoInvokeClient {    
   
    public static void main(String[] args) {    
        Service serviceModel = new ObjectServiceFactory().create(IPersonService.class);    
   
        XFire xfire = XFireFactory.newInstance().getXFire();    
        XFireProxyFactory factory = new XFireProxyFactory(xfire);    
        String serviceUrl = "http://127.0.0.1:8080/xfire/services/PersonService";    
   
        IPersonService client = null;    
        try {    
            client = (IPersonService) factory.create(serviceModel, serviceUrl);    
        } catch (MalformedURLException e) {    
            System.out.println("Client call webservice has exception: "+ e.toString());    
        }    
   
        String result1 =client.sayHello("张三");    
            
    }    
}  
  
 二、直接通过url调用, 不用客户端提供接口类

Java代码 
package com.wujianjun.xfire.client;    
   
import java.net.MalformedURLException;    
import java.net.URL;    
   
import org.codehaus.xfire.client.Client;    
   
public class UrlInvokeClient {    
   
    public static void main(String[] args) {    
        Client client = null;    
        try {    
            client = new Client(new URL("http://127.0.0.1:8080/xfire/PersonService.ws?wsdl"));    
            Object[] result1 = client.invoke("sayHello", new Object[] {"张三"});    
            System.out.println(result1[0]);    
        } catch (MalformedURLException e) {    
            e.printStackTrace();    
        } catch (Exception e) {    
            e.printStackTrace();    
        }    
    }    
}   

猜你喜欢

转载自newerdragon.iteye.com/blog/1927172