使用xfire方式調用webservice接口不需要配置services.xml等文件,只需要java程序即可調用。
代碼如下:
public static void main(String[] args) throws MalformedURLException {
String serviceURL = "http://localhost:8080/project_name/WSProject.ws";
Service serviceModel = new ObjectServiceFactory().create(InterfaceName.class);
InterfaceName serviceImp = (ITravelToBts)new XFireProxyFactory().create(serviceModel, serviceURL);
........
}
InterfaceName爲定義的websevice接口類,並不是實現類。
注意需要導入的類
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
serviceImp變量是webservice接口的實現類。