jax-ws soap
2794 ワード
public class User {
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
@WebService()
public interface IMyService {
@WebResult(name="addResult")
public int add(@WebParam(name="a")int a,@WebParam(name="b")int b);
@WebResult(name="minusResult")
public int minus(@WebParam(name="a")int a,@WebParam(name="b")int b);
@WebResult(name="loginUser")
public User login(@WebParam(name="username")String username,@WebParam(name="password")String password);
}
@WebService(endpointInterface="org.zttc.service.IMyService")
public class MyServiceImpl implements IMyService {
@Override
public int add(int a, int b) {
System.out.println(a+"+"+b+"="+(a+b));
return a+b;
}
@Override
public int minus(int a, int b) {
System.out.println(a+"-"+b+"="+(a-b));
return a-b;
}
@Override
public User login(String username, String password) {
System.out.println(username+" is logining");
User user = new User();
user.setId(1);
user.setUsername(username);
user.setPassword(password);
return user;
}
}
public class MyServer {
public static void main(String[] args) {
String address = "http://localhost:8888/ns";
Endpoint.publish(address, new MyServiceImpl());
}
}
public class TestClient {
public static void main(String[] args) {
try {
// wsdl url
URL url = new URL("http://localhost:8888/ns?wsdl");
// Qname
QName sname = new QName("http://service.zttc.org/", "MyServiceImplService");
//
Service service = Service.create(url,sname);
//
IMyService ms = service.getPort(IMyService.class);
System.out.println(ms.add(12,33));
// , IMyServie
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}