标签:main 不同 bre publish inter str .com tin min
package service; public class UserBean { private String userId; private String userName; private String passWord; //隐藏getset方法 }
package service; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; /** * 这是一个web服务 * @author Administrator * */ @WebService public interface UserService { /** * 获取用户 * @return */ @WebResult(name = "getUserResult") public UserBean getUser(); /** * 设置用户 * @param user */ public void setUser(@WebParam(name = "userBean") UserBean user); }
package service; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService(endpointInterface="service.UserService") public class UserServiceimpl implements UserService { @Override public UserBean getUser() { UserBean user = new UserBean(); user.setPassWord("123"); user.setUserId("001"); user.setUserName("服务端返回的用户"); return user; } @Override public void setUser(UserBean user) { if (user != null) { System.out.println("客户端设置的用户=" + user); } } }
package publish; import javax.xml.ws.Endpoint; import service.UserServiceimpl; public class TestPublish { public static void main(String[] args) { Endpoint.publish("http://localhost:3030/userBean", new UserServiceimpl()); System.out.println("发布成功....."); } }
package test; import java.rmi.RemoteException; import service.UserBean; import service.UserService; import service.UserServiceProxy; public class TestMain { public static void main(String[] args) throws RemoteException { /** * 获取服务端返回的用户 */ UserService userService=new UserServiceProxy().getUserService(); UserBean user=userService.getUser(); System.out.println(user.getUserId()+"\t"+user.getUserName()); /** * 客户端设置用户 */ UserBean userbean=new UserBean(); userbean.setUserId("2"); userbean.setUserName("客户端设置的用户"); userbean.setPassWord("123520"); new UserServiceProxy().setUser(userbean); } }
结果:
标签:main 不同 bre publish inter str .com tin min
原文地址:http://www.cnblogs.com/shyroke/p/7655255.html