标签:
package xfireTest; public interface XFireTestService { public String test(String cont); }
package xfireTest.xfireTestImp; import xfireTest.XFireTestService; public class XFireTestImp implements XFireTestService { @Override public String test(String cont) { cont = "webService收到消息:" + cont; return cont; } }
<service xmlns="http://xfire.codehaus.org/config/1.0"> <!-- webService服务的名称 --> <name>XFireTest</name> <namespace>http://xfireTest/XFireTestService</namespace> <!-- 自己所写的接口路径 --> <serviceClass> xfireTest.XFireTestService </serviceClass> <!-- 实现类路径 --> <implementationClass> xfireTest.xfireTestImp.XFireTestImp </implementationClass> </service>
package test; public interface XFireTestService { public String test(String cont); }
package test; import org.codehaus.xfire.XFireFactory; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; public class CallWebServiceTest1 { public static void main(String[] args) { Service srModel = new ObjectServiceFactory() .create(XFireTestService.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory .newInstance().getXFire());// 创建工厂实例 String helloURL = "http://localhost:8082/xfireTest/services/XFireTest"; try { XFireTestService service = (XFireTestService) factory.create( srModel, helloURL); System.out.println(service.test("测试")); } catch (Exception e) { throw new RuntimeException(e); } } }
package xfireTest; import java.io.Serializable; public class UserModel implements Serializable { /** * */ private static final long serialVersionUID = -8344776127885486411L; public UserModel() { super(); } public UserModel(String userName, int age) { super(); this.userName = userName; this.age = age; } /** * 用户名 */ private String userName; /** * 用户年龄 */ private int age; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "UserModel [userName=" + userName + ", age=" + age + "]"; } }
package xfireTest; import javax.jws.WebParam; import javax.jws.WebService; @WebService(serviceName = "UserService", targetNamespace = "http://xfireTest/UserService") public interface UserService { public UserModel addUser(@WebParam(name = "user") UserModel user); }
package xfireTest.xfireTestImp; import xfireTest.UserModel; import xfireTest.UserService; public class UserServiceImp implements UserService { @Override public UserModel addUser(UserModel user) { // System.out.println(user); System.out.println(user.getUserName() + ":" + user.getAge()); return user; } }
<service xmlns="http://xfire.codehaus.org/config/1.0"> <!-- webService服务的名称 --> <name>UserService</name> <namespace>http://xfireTest/UserService</namespace> <!-- 自己所写的接口路径 --> <serviceClass> xfireTest.UserService </serviceClass> <!-- 实现类路径 --> <implementationClass> xfireTest.xfireTestImp.UserServiceImp </implementationClass> </service>
package test; import org.codehaus.xfire.XFireFactory; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; public class CallWebServiceTest2 { public static void main(String[] args) { Service srModel = new ObjectServiceFactory().create(UserService.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory .newInstance().getXFire());// 创建工厂实例 String helloURL = "http://localhost:8082/xfireTest/services/UserService"; try { UserService service = (UserService) factory.create(srModel, helloURL); UserModel user = new UserModel(); user.setAge(22); user.setUserName("test"); System.out.println(service.addUser(user)); } catch (Exception e) { throw new RuntimeException(e); } } }
package test; import javax.jws.WebParam; import javax.jws.WebService; @WebService(serviceName = "UserService", targetNamespace = "http://xfireTest/UserService") public interface UserService { public UserModel addUser(@WebParam(name = "user") UserModel user); }
package test; import java.io.Serializable; public class UserModel implements Serializable { /** * */ private static final long serialVersionUID = 9024481738536854407L; public UserModel() { super(); } public UserModel(String userName, int age) { super(); this.userName = userName; this.age = age; } /** * 用户名 */ private String userName; /** * 用户年龄 */ private int age; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "UserModel [userName=" + userName + ", age=" + age + "]"; } }
java程序调用xfire发布的webService服务(二)
标签:
原文地址:http://blog.csdn.net/tuzongxun/article/details/51612367