定义接口
package com.entity;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="User")
public class User {
private String id;
private String uid;
private String pwd;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
定义实现类
package com.entity;
import javax.jws.WebService;
@WebService(targetNamespace="http://liaomin")
public class UserServiceImpl implements UserService {
public void addUser(User user) {
// TODO Auto-generated method stub
System.out.println("adduser");
}
public boolean checkUser(User user) {
// TODO Auto-generated method stub
return false;
}
}
发布服务
1》方法1
Endpoint.publish("http://localhost:8088/abc", new UserServiceImpl());
2》方法2
JaxWsServerFactoryBean soapFactoryBean = new JaxWsServerFactoryBean();
soapFactoryBean.getInInterceptors().add(new LoggingInInterceptor());
soapFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
// 注意这里是实现类不是接口
soapFactoryBean.setServiceClass(UserServiceImpl.class);
soapFactoryBean.setAddress("http://localhost:8088/abc");
soapFactoryBean.create();