3.创建Web Service,弹窗详细设置如图:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>HelloWorld</name> <serviceClass>hellows.IHelloWorld</serviceClass> <implementationClass> hellows.HelloWorldImpl </implementationClass> <style>wrapped</style> <use>literal</use> <scope>application</scope> </service></beans>
package hellows; //Generated by MyEclipse public interface IHelloWorld { public String example(String message); }
package hellows; //Generated by MyEclipse public class HelloWorldImpl implements IHelloWorld { public String example(String message) { System.out.println(this); return "你好,这是我的第一个Web Service,你输入的消息是:"+message; } }
package wsclient; import java.net.MalformedURLException; import hellows.IHelloWorld; import org.codehaus.xfire.XFireFactory; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.*; import org.codehaus.xfire.service.binding.ObjectServiceFactory; public class HelloWSClient { public static void main(String[] args) { Service srvcModel = new ObjectServiceFactory() .create(IHelloWorld.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory .newInstance().getXFire()); String helloWorldURL = "http://127.0.0.1:8080/HelloWorldXFire/services/HelloWorld"; try { IHelloWorld srvc = (IHelloWorld) factory.create( srvcModel, helloWorldURL); String result = srvc.example("hello world Java 客户端测试"); System.out.print(result); } catch (MalformedURLException e) { e.printStackTrace(); } } }