Web service jws自带测试例子

发表于:2014-3-19 11:15

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:下一个路口我等你    来源:51Testing软件测试网采编

  新建一个服务端项目:
  1、定义一个接口如下:
/**
* 定义webservices接口
* @author Administrator
*
*/
@WebService
public interface IHelloService {
public String sayHello(String name);
public User  getUser(User user);
}
  2.实现接口
/**
* 实现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;
}
}
  3、启动服务(执行下列main函数)
public class TestService {
public static void main(String[] args) {
//服务地址
String address="http://localhost:8989/u";
Endpoint.publish(address, new HelloServiceImpl());
}
}
  4、在浏览器上输入:http://127.0.0.1:8989/u?wsdl 看到以下信息:
<!-- 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>
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号