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 ...
随机推荐
- db_link
1.查询 SYSDBA登录, sys登录 SELECT * FROM SYS.link$; select owner,object_name from dba_objects where obj ...
- webAppbuilder微件使用教程3 地理处理微件
webAppbuilder微件使用教程 --微件使用进阶地理处理微件 By 李远祥 地理处理是GIS解决问题的关键部分,也是其灵魂所在.由于WebAppBuilder框架的限制,用户如果想要非常灵活的 ...
- ContextMenu控件引用以及不用v4包的方法
最近想撸个APP出来玩玩,本想用Yalantis出的SideMenu,结果因为依赖问题放弃了,改用他们家的ContextMenu. 如果你用了v4包 那么问题就比较简单了,直接打开项目中app中的bu ...
- sql增删查改
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- iOS企业版APP分发上线流程和注意事项
0.准备 1]$299/year的企业级开发账号. 2]制作分发证书和描述文件,并下载安装到本机. 3]Xcode编译通过,真机测试通过的源码. 1.打包前配置 1]Xcode 打开项目,common ...
- Baidu图表插件--Eharts使用(柱状图)
官网链接:http://echarts.baidu.com/index.html 官网的demo,api都很详细:我就分享下我的学习步骤 首先定义一个显示图标的区域: <div id=" ...
- ssh免密码和ssh-copy-id命令
Linux系统配置免密码的方式: 1:ssh-keygen -t rsa 生成密钥 2:ssh-copy-id -i ~/.ssh/id_rsa.pub 127.0.0.1 把本机的公钥追到jifen ...
- IOS缓存管理之PINCache使用
前言: 今年重点在于公司iOS架构的梳理工作,上周整理了http请求接口管理与解耦,接下来准备整理一下项目中的缓存处理,目前项目中使用的是PINCache,去年加入这个开源框架时并没有对这个框架进行了 ...
- css中书写小三角
我们在开发过程中,有很多的方向标签不是图片,而是用css方法书写上去的. 首先我们要了解原理,border的边框的脚步是45度角. 向左方向: width:0px: height:0px: borde ...
- 浅谈V8引擎中的垃圾回收机制
最近在看<深入浅出nodejs>关于V8垃圾回收机制的章节,转自:http://blog.segmentfault.com/skyinlayer/1190000000440270 这篇文章 ...