WebService从服务端到客户端的用例
1、首先编写Wsdl(基于契约优先的方式),要注意的是命名空间(若是使用include或import)最好使用一致的,代码如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.xiaoqiaolv/ws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="UserServiceImpl"
targetNamespace="http://www.xiaoqiaolv/ws">
<wsdl:types>
<xsd:schema targetNamespace="http://www.xiaoqiaolv/ws">
<!-- <xsd:include schemaLocation="UserSchema.xsd"/> -->
<!-- <xsd:import namespace="http://www.xiaoqiaolv/ws" schemaLocation="UserSchema.xsd"/>--> <xsd:element name="add" type="tns:add"/>
<xsd:element name="addResponse" type="tns:addResponse"/>
<xsd:element name="delete" type="tns:delete"/>
<xsd:element name="deleteResponse" type="tns:deleteResponse"/>
<xsd:element name="login" type="tns:login"/>
<xsd:element name="loginResponse" type="tns:loginResponse"/>
<xsd:element name="list" type="tns:list"/>
<xsd:element name="listResponse" type="tns:listResponse"/> <xsd:complexType name="add">
<xsd:sequence>
<xsd:element name="user" type="tns:user"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="addResponse">
<xsd:sequence/>
</xsd:complexType> <xsd:complexType name="delete">
<xsd:sequence>
<xsd:element name="username" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="deleteResponse">
<xsd:sequence/>
</xsd:complexType> <xsd:complexType name="list">
<xsd:sequence/>
</xsd:complexType>
<xsd:complexType name="listResponse">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="user" type="tns:user"/>
</xsd:sequence>
</xsd:complexType> <xsd:complexType name="login">
<xsd:sequence>
<xsd:element name="username" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="loginResponse">
<xsd:sequence/>
</xsd:complexType>
<xsd:complexType name="user">
<xsd:sequence>
<xsd:element name="id" type="xsd:int"/>
<xsd:element name="username" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types> <wsdl:message name="addMessage">
<wsdl:part element="tns:add" name="add"/>
</wsdl:message>
<wsdl:message name="addResponseMessage">
<wsdl:part element="tns:addResponse" name="addResponse"/>
</wsdl:message> <wsdl:message name="deleteMessage">
<wsdl:part name="delete" element="tns:delete"/>
</wsdl:message>
<wsdl:message name="deleteResponseMessage">
<wsdl:part name="deleteResponse" element="tns:deleteResponse"/>
</wsdl:message> <wsdl:message name="listMessage">
<wsdl:part name="list" element="tns:list"/>
</wsdl:message>
<wsdl:message name="listResponseMessage">
<wsdl:part name="listResponse" element="tns:listResponse"/>
</wsdl:message> <wsdl:message name="loginMessage">
<wsdl:part name="login" element="tns:login"/>
</wsdl:message>
<wsdl:message name="loginResponseMessage">
<wsdl:part name="loginResponse" element="tns:loginResponse"></wsdl:part>
</wsdl:message> <wsdl:portType name="UserService">
<wsdl:operation name="add">
<wsdl:input message="tns:addMessage"/>
<wsdl:output message="tns:addResponseMessage"/>
</wsdl:operation> <wsdl:operation name="delete">
<wsdl:input message="tns:deleteMessage"/>
<wsdl:output message="tns:deleteResponseMessage"/>
</wsdl:operation> <wsdl:operation name="list">
<wsdl:input message="tns:listMessage"/>
<wsdl:output message="tns:listResponseMessage"/>
</wsdl:operation> <wsdl:operation name="login">
<wsdl:input message="tns:loginMessage"/>
<wsdl:output message="tns:loginResponseMessage"/>
</wsdl:operation>
</wsdl:portType> <wsdl:binding name="userBinding" type="tns:UserService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="add">
<soap:operation soapAction="http://www.xiaoqiaolv/ws/add"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation> <wsdl:operation name="delete">
<soap:operation soapAction="http://www.xiaoqiaolv/ws/delete"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation> <wsdl:operation name="login">
<soap:operation soapAction="http://www.xiaoqiaolv/ws/login"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation> <wsdl:operation name="list">
<soap:operation soapAction="http://www.xiaoqiaolv/ws/list"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="UserServiceImpl">
<wsdl:port binding="tns:userBinding" name="UserServiceImplPort">
<soap:address location="http://localhost:9999/ws"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
2、实现服务器端的应用实现,这个就不加代码了,根据wsdl文档用wsimport生成服务,只取出接口service,然后其他的和我们正常的web开发都一致。
3、服务端发布服务:public static void main(String[] args) {
Endpoint.publish("http://localhost:9999/ws", new UserServiceImpl());
}
4、实现客户端:根据服务网址http://localhost:9999/ws,生成服务,得到所有以.java为后缀的类,把整个包包含在自己的项目中
5、编写测试类:代码如下:
public class Test {
private UserService userService;
private UserServiceImpl userServiceImpl;
public void testWsdl(){
try {
URL url = new URL("http://localhost:9999/ws?wsdl");
QName qname = new QName("http://www.xiaoqiaolv/ws","UserServiceImpl");
userServiceImpl = new UserServiceImpl(url,qname);
userService = userServiceImpl.getUserServiceImplPort();
User user = new User();
user.setUsername("aaa");
user.setPassword("1111");
user.setId(21212);
userService.add(user);
List<User> list = userService.list();
for(User u:list){
System.out.println(u.getUsername());
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
new Test().testWsdl();
}
}
6、有问题的话可以打开tcpmon,对接口服务进行监听,查看客户端与服务端传递的信息java -jar tcpmon.jar
WebService从服务端到客户端的用例的更多相关文章
- spring mvc + mybaties + mysql 完美整合cxf 实现webservice接口 (服务端、客户端)
spring-3.1.2.cxf-3.1.3.mybaties.mysql 整合实现webservice需要的完整jar文件 地址:http://download.csdn.net/detail/xu ...
- myeclipse-建立webservice服务端和客户端
一.建立webservice服务端: 1.新建一个web service project,名称为webservice_server截图如下,点击finish. 2.选择工程,点击右键,选择new-&g ...
- 使用Apache CXF开发WebServices服务端、客户端
在前一篇的博客中,我使用Xfire1.x来开发了WebServies的服务端. 但是如果你访问Apache的官网,可以看到xfire已经被合并了. 最新的框架叫做CXF. Apache CXF = C ...
- WebService-03-使用CXF开发服务端和客户端
写在前面的话 前面两节说了使用Java提供的包开发服务端和客户端,现在使用CXF来开发,CXF提供了两个类发而服务,一个是ServerFactoryBean,另一个是JaxWsServerFactor ...
- C# 编写WCF简单的服务端与客户端
http://www.wxzzz.com/1860.html Windows Communication Foundation(WCF)是由微软开发的一系列支持数据通信的应用程序框架,可以翻译为Win ...
- asp.net获取服务端和客户端信息
asp.net获取服务端和客户端信息 获取服务器名:Page.Server.ManchineName获取用户信息:Page.User 获取客户端电脑名:Page.Request.UserHostNam ...
- python thrift 服务端与客户端使用
一.简介 thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, Erlang, ...
- IE8下服务端获取客户端文件的路径为C:/fakePath问题的解决方案
上一篇文章上提到,IE8下服务端获取客户端文件的路径时,会变成C:/fakePath问题,于是乎通过文件路径去获得文件大小就失败了. 上网搜了一下,主要原因是IE8因为安全考虑,在上传文件时屏蔽了真实 ...
- 如何排查APP服务端和客户端是否支持ATS
服务端排查 取得客户端直接连接的服务端域名及端口,例如mob.com.cn,端口443,即HTTPS默认端口.针对公网可访问的生产环境地址,建议使用的在线监测工具.https://wosign.ssl ...
随机推荐
- Express之get,pos请求参数的获取
Express的版本4.X Get query参数的获取 url假设:http://localhost:3000/users/zqzjs?name=zhaoqize&word=cool& ...
- java打包jar,war,ear包的作用、区别
java的打包jar,war,ear包的作用,区别,打包方式. a) 作用与区别 i. jar: 通常是开发时要引用通用(JAVA)类,打成包便于存放管理 ii. war ...
- PHP文本处理之中文汉字字符串转换为数组
在PHP中我们可以通过str_split 将字符串转换为数组,但是却对中文无效,下面记录一下个人将中文字符串转换为数组的方法. 用到的PHP函数 mb_strlen - 获取字符串的长度 mb_sub ...
- Spring 中使用Quartz实现任务调度
前言:Spring中使用Quartz 有两种方式,一种是继承特定的基类:org.springframework.scheduling.quartz.QuartzJobBean,另一种则不需要,(推荐使 ...
- JS打开摄像头并截图上传
直入正题,JS打开摄像头并截图上传至后端的一个完整步骤 1. 打开摄像头主要用到getUserMedia方法,然后将获取到的媒体流置入video标签 2. 截取图片主要用到canvas绘图,使用dra ...
- Sublime Text 3 修改配色主题【侧边框之...】
Sublime Text3 是挺喜欢的一款编辑器,一周五天朝九晚六面对,而默认的侧边栏颜色总显得不尽人意.右侧的代码高亮[color_scheme:Monokai]挺喜欢的,心里就想着如何把侧边栏也给 ...
- 用js写出光棒效应的两种方法与jquery的两中方法
<script src="js/jQuery1.11.1.js" type="text/javascript"></script> &l ...
- php投票练习
一.题目要求:建立如下两个数据库,实现投票和%的统计结果: 二.具体编写方法: (1).建立数据库: 里面的蓝色背景的表格名称就是我们所需的表格! 表格内容如下: 表名:diaoyantimu 表名: ...
- linux网卡配置
6.3网卡配置 DEVICE=eth0 TYPE=Ethernet BOOTPROTO=dhcp ONBOOT=yes NETMASK=255.255.255.0 GETWAY=192.168.1.2 ...
- c#基础语句——循环语句(for、while、foreach)
循环类型:for.while.foreach 循环四要素:初始条件-->循环条件-->循环体-->状态改变 1.for 格式: for(初始条件:循环条件:状态改变) {循环体(br ...