更新时间:2022-09-21 22:34:21
/**
* 定义webservices接口
* @author Administrator
*
*/
@WebService
public interface IHelloService {
public String sayHello(String name);
public User getUser(User user);
}
|
/**
* 实现webservices接口
* @author Administrator
*
*/endpointInterface 实现的接口类
@WebService(endpointInterface="com.chni.webservies.IHelloService")
public class HelloServiceImpl implements IHelloService {
public User getUser(User user) {
// TODO Auto-generated method stub
return null;
}
public String sayHello(String name) {
// TODO Auto-generated method stub
return name;
}
}
|
public class TestService {
public static void main(String[] args) {
//服务地址
String address="http://localhost:8989/u";
Endpoint.publish(address, new HelloServiceImpl());
}
}
|
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><definitions targetNamespace="http://impl.webservies.chni.com/" name="HelloServiceImplService"><import namespace="http://webservies.chni.com/" location="http://127.0.0.1:8989/u?wsdl=1"/><binding name="HelloServiceImplPortBinding" type="ns1:IHelloService"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="getUser"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation><operation name="sayHello"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="HelloServiceImplService"><port name="HelloServiceImplPort" binding="tns:HelloServiceImplPortBinding"><soap:address location="http://127.0.0.1:8989/u"/></port></service></definitions> |
public class TestMail {
public static void main(String[] args) {
//建立客户端(HelloServiceImplService 这个往什么地方来的去分析一下wsdl文件中有个service name=“new的这个HelloServiceImplService类”)建议还是去网上看看
IHelloService cilent=new HelloServiceImplService().getHelloServiceImplPort();
String abc=cilent.sayHello("XXX");
System.out.println(abc);
}
}
|