Client call of xfire of webservice

Now let's look at the client call of xfire, there are two ways:

1. Call through the interface class provided by the server.

Java code copy code
  1. package com.wujianjun.xfire.client;   
  2.   
  3. import java.net.MalformedURLException;   
  4. import java.util.List;   
  5.   
  6. import org.codehaus.xfire.XFire;   
  7. import org.codehaus.xfire.XFireFactory;   
  8. import org.codehaus.xfire.client.XFireProxyFactory;   
  9. import org.codehaus.xfire.service.Service;   
  10. import org.codehaus.xfire.service.binding.ObjectServiceFactory;   
  11.   
  12. import com.wujianjun.xfire.domain.Person;   
  13. import com.wujianjun.xfire.spring.IPersonService;   
  14.   
  15. public class PojoInvokeClient {   
  16.   
  17.     public static void main(String[] args) {   
  18.         Service serviceModel = new ObjectServiceFactory().create(IPersonService.class);   
  19.   
  20.         XFire xfire = XFireFactory.newInstance().getXFire();   
  21.         XFireProxyFactory factory = new XFireProxyFactory(xfire);   
  22.         String serviceUrl = "http://127.0.0.1:8080/xfire/services/PersonService";   
  23.   
  24.         IPersonService client = null;   
  25.         try {   
  26.             client = (IPersonService) factory.create(serviceModel, serviceUrl);   
  27.         } catch (MalformedURLException e) {   
  28.             System.out.println("Client call webservice has exception: "+ e.toString());   
  29.         }   
  30.   
  31.         String result1 =client.sayHello("Zhang San");   
  32.            
  33.     }   

 2. Call directly through the url, without the client providing an interface class

Java code copy code
  1. package com.wujianjun.xfire.client;   
  2.   
  3. import java.net.MalformedURLException;   
  4. import java.net.URL;   
  5.   
  6. import org.codehaus.xfire.client.Client;   
  7.   
  8. public class UrlInvokeClient {   
  9.   
  10.     public static void main(String[] args) {   
  11.         Client client = null;   
  12.         try {   
  13.             client = new Client(new URL("http://127.0.0.1:8080/xfire/PersonService.ws?wsdl"));   
  14.             Object[] result1 = client.invoke("sayHello", new Object[] {"张三"});   
  15.             System.out.println(result1[0]);   
  16.         } catch (MalformedURLException e) {   
  17.             e.printStackTrace ();   
  18.         } catch (Exception e) {   
  19.             e.printStackTrace ();   
  20.         }   
  21.     }   
  22. }  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326522997&siteId=291194637