![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5e60616b2746ffb17f76f80459dfad47.png)
一、服务端
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0c006c503cc7beff336905ce6ccb203e.png)
1.1、UserBean
package com.dgut.bean;
public class UserBean {
private int id;
private String name;
private int age;
private String sex;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
1.2、UserDao
package com.dgut.dao;
import javax.jws.WebService;
import com.dgut.bean.UserBean;
@WebService
public class UserDao {
public void hello() {
System.out.println("hello world!!");
}
public UserBean findUserBeanById(int id) {
UserBean userBean=new UserBean();
userBean.setId(id);
userBean.setName("王二毛");
userBean.setAge(18);
userBean.setSex("男");
return userBean;
}
}
1.3、PublishUserService
package com.dgut.service;
import javax.xml.ws.Endpoint;
import com.dgut.dao.UserDao;
public class PublishUserService {
public static void main(String[] args) {
System.out.println("服务端开始发布初始化...");
if (Endpoint.publish("http://localhost:8989/helloworld", new UserDao()) != null) {
System.out.println("服务端发布成功");
}
}
}
二、客户端
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3fd9583a569b85b3bf18e31057b9f165.png)
2.1、UserInvoke
package com.dgut.client;
import com.dgut.user.UserBean;
import com.dgut.user.UserDao;
import com.dgut.user.UserDaoService;
public class UserInvoke {
public static void main(String[] args) {
UserDao userDao = null;
UserDaoService userDaoService = new UserDaoService();
userDao = userDaoService.getUserDaoPort();
UserBean user=userDao.findUserBeanById(1);
System.out.println(user.getName());
System.out.println(user.getAge());
System.out.println(user.getSex());
}
}
三、结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e43bba97cdb1f5913d63e4639a461d9d.png)