最普通的XFire Client代码

需要把Service接口,相应的javabean, aegis文件打成jar包,部署到Client工程的classpath中 

使用如下代码访问WebService

 

package  client;

import  java.net.MalformedURLException;

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  Test.User;

public   class  TestWS2  {

    
/**
     * 
@param args
     
*/

    
public static void main(String[] args) {
        Service srvcModel 
= new ObjectServiceFactory().create(IHelloWorldService.class);
        XFireProxyFactory factory 
= new XFireProxyFactory(XFireFactory.newInstance().getXFire());
        String helloWorldURL 
= "http://localhost:8080/XFireStudy/services/IHelloWorldService";
        
try {
            IHelloWorldService srvc 
= (IHelloWorldService) factory.create(
                    srvcModel, helloWorldURL);
            System.out.print(srvc.HelloWorld(
new User("gaoxiang","1234")).getUsername());
        }
 catch (MalformedURLException e) {
            e.printStackTrace();
        }

    }


}

你可能感兴趣的:(webservice,String,service,jar,Class,import)