webservice(二)简单实例
1、建立WSDL文件
建立WSDL的工具很多,eclipse、zendstudio、vs都可以,我个人建议自己写,熟悉结构,另外自动工具对xml schame类型支持在类型中可能会报错。
下面是我自己写的模板:
- <?xml version ='1.0' encoding ='UTF-8' ?>
- <definitions name='自定义名称'
- targetNamespace='目标命名空间(WSDL所在地址)'
- <!--tns自定义目标空间,下面会用到-->
- xmlns:tns='目标命名空间(WSDL所在地址)'
- xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
- xmlns:xsd='http://www.w3.org/2001/XMLSchema'
- xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
- xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
- xmlns='http://schemas.xmlsoap.org/wsdl/'>
- <!--<types> 元素定义 web service 使用的数据类型,WSDL 使用 XML Schema 语法来定义数据类型,这里可以定义一些Schema不支持的类型-->
- <types>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- targetNamespace="目标命名空间(WSDL所在地址)">
- </xsd:schema>
- </types>
- <!--
- <message> 元素可定义每个消息的部件,以及相关联的数据类型。
- 请求-响应是最普通的操作类型,不过 WSDL 定义了四种类型:
- One-way 此操作可接受消息,但不会返回响应。
- Request-response 此操作可接受一个请求并会返回一个响应。(常用)
- Solicit-response 此操作可发送一个请求,并会等待一个响应。
- Notification 此操作可发送一条消息,但不会等待响应。
- -->
- <message name='请求消息名称(方法名+Request)'>
- <part name="term" type="xsd:string"/>
- </message>
- <message name='响应消息名称(方法名+Response)'>
- <part name="value" type="xsd:string"/>
- </message>
- <!--
- <portType> 元素是最重要的 WSDL 元素。它可描述一个 web service、可被执行的操作,以及相关的消息。
- 它告诉你去哪个WebService的连接点,扮演了一个控制者。
- -->
- <portType name='执行的操作名称(binding的type与其对应)'>
- <operation name='执行操作的方法'>
- <input message='tns:*Request'/>
- <output message='tns:*response'/>
- </operation>
- </portType>
- <!--<binding> 元素为每个端口定义消息格式和协议细节-->
- <binding name='Binding的名称,与service的port名称对应' type='指向用于Binding的端口(tns(前缀):PortType名称)'>
- <!--style:属性可取值 "rpc" 或 "document",ransport:属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP-->
- <soap:binding style='rpc'
- transport='http://schemas.xmlsoap.org/soap/http'/>
- <!--operation 元素定义了每个端口提供的操作符,对于每个操作,相应的 SOAP 行为都需要被定义-->
- <operation name='GetCallDetailRecords'>
- <soap:operation soapAction='http://www.cwtservice.cn/newOperation/'/>
- <input>
- <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
- encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
- </input>
- <output>
- <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
- encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
- </output>
- </operation>
- </binding>
- <!--<service>包含一个或者多个port元素,每个port元素表示一个不同的Web服务-->
- <service name='服务名称'>
- <port name='Binding名称' binding='tns:Binding名称'>
- <soap:address location='http://目标命名空间(WSDL所在地址)/service.php'/>
- </port>
- </service>
- </definitions>
2、在service目录下建立myphone.wsdl
- <?xml version ='1.0' encoding ='UTF-8' ?>
- <definitions name='phonebook'
- targetNamespace='http://www.mysoapservice.cn/'
- xmlns:tns='http://www.mysoapservice.cn/'
- xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
- xmlns:xsd='http://www.w3.org/2001/XMLSchema'
- xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
- xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
- xmlns='http://schemas.xmlsoap.org/wsdl/'>
- <types>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- targetNamespace="http://www.mysoapservice.cn/">
- </xsd:schema>
- </types>
- <message name='GetPhoneBookRequest'>
- <part name="name" type="xsd:string"/>
- </message>
- <message name='GetPhoneBookResponse'>
- <part name="phonebookInfo" type="xsd:string"/>
- </message>
- <portType name='PhoneBookToEveryOneProt'>
- <operation name='GetPhoneBook'>
- <input message='tns:GetPhoneBookRequest'/>
- <output message='tns:GetPhoneBookResponse'/>
- </operation>
- </portType>
- <binding name='PhoneBookSOAP' type='tns:PhoneBookToEveryOneProt'>
- <soap:binding style='rpc'
- transport='http://schemas.xmlsoap.org/soap/http'/>
- <operation name='GetPhoneBook'>
- <soap:operation soapAction='http://www.cwtservice.cn/newOperation/'/>
- <input>
- <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
- encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
- </input>
- <output>
- <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
- encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
- </output>
- </operation>
- </binding>
- <service name='PhoneBookService'>
- <port name='PhoneBookSOAP' binding='tns:PhoneBookSOAP'>
- <soap:address location='http://www.mysoapservice.cn/service.php'/>
- </port>
- </service>
- </definitions>
3、修改service.php
- <?php
- function GetPhoneBook($name){
- $pbook="Zhangsan,13888888888,friend,8888@163.com";
- return $pbook;
- }
- $server = new SoapServer("myphone.wsdl");
- $server->addFunction("GetPhoneBook");
- $server->handle ();
- ?>
4、修改client.php
- <?php
- header('Content-Type:text/html;charset=utf-8');
- $client = new SoapClient("http://www.mysoapservice.cn/service.php?WSDL" , array('trace'=>true));
- var_dump($client->__getTypes());
- try {
- $response = $client->GetPhoneBook('zhang');
- var_dump($response);
- }catch (SoapFault $sf){
- var_dump($sf);
- print ($client->__getLastRequest());
- print ($client->__getLastResponse());
- }
- ?>
测试:
http://www.mysoapclient.cn/client.php
转载:http://blog.csdn.net/cwt0408/article/details/6952936
转载于:https://www.cnblogs.com/yuwensong/p/4387163.html
webservice(二)简单实例相关推荐
- webservice实例java_Java WebService(实战) 简单实例
一.准备工作(以下为本实例使用工具) 1.MyEclipse10.7.1 2.JDK 1.6.0_22 二.创建服务端 1.创建[Web Service Project],命名为[TheService ...
- vue 调用webservice_js跨域调用WebService的简单实例
步骤1. 在web.config中的system.web节点里加入 步骤2.webservice代码 using System; using System.Collections.Generic; u ...
- 用Java 开发 WebService Axis简单实例
用 Java 开发 WebService Axis 简单实例 在开发之前, 先了解一下AXIS,axis目前出现的2版本以其灵活性,快速开发工具的集成高于xfire而使用者居其上.用Eclipse开发 ...
- java开发webservice简单实例_jsp实现的webservice的简单实例
jsp webservice用到的比较少但是用到就是一个大东西了经常用过其它的api形式了而webservice用到不多,下面我们来看一篇关于jsp实现的webservice的简单实例吧,具体如下. ...
- 使用CXF发布WebService服务简单实例
一.说明: 前面介绍了使用axis2来发布Webservice服务,现在介绍一种更popular,更高效的Webservice服务发布技术:CXF Apache CXF = Celtix + XFir ...
- php使用webservivce_使用zeng studio 创建的php调用webservice soap简单实例
这两天一直在研究webservice soap是个什么东西,究竟怎么创建webservice,又如何用php调用webservice的借口,经过奋战,终于总算弄懂一点的.然后我做了一个webservi ...
- 关于webservice的异步调用简单实例
于webservice的异步调用简单实例 无论在任何情况下,被调用方的代码无论是被异步调用还是同步调用的情况下,被调用方的代码都是一样的, 下面,我们就以异步调用一个webservice 为例作说明. ...
- Hibernate搭建开发环境+简单实例(二)
2019独角兽企业重金招聘Python工程师标准>>> Hibernate是非常典型的持久层框架,持久化的思想是非常值得我们学习和研究的.这篇博文,我们主要以实例的形式学习Hiber ...
- php 二位数组随机,PHP多维数组 php打乱数组二维数组多维数组的简单实例
php中的shuffle函数只能打乱一维数组,有什么办法快速便捷的打乱多维数组?手册上提供了 上面这个是针对二维数组的! 下面针对多维数组的乱序方法?尽可能的方便快速: 以下函数也是出自php手册,可 ...
最新文章
- Yii使用CTreeView树
- 同时删除两张表的数据_把数据表中对应工作表的数据首先删除,然后导入数据...
- 好程序员Web前端教程分享JavaScript开发技巧
- postgresql 创建用户_国内源安装postgresql
- java home not set_Error: JAVA_HOME is not set and could not be found.
- LeetCode - 3Sum Closest
- Java:如何创建轻量级数据库微服务
- CodeForces - 1144F搜索+简单图论
- 私钥公钥学习心得(二)比特币与支付宝
- Spring Validation校验
- 设置mysql acquisition_MYSQL 7*24 高可用环境的部署
- Java 实现线性运动界面_java 实现顺序结构线性列表
- 扫描仪twain驱动是什么_扫描仪无法显示怎么办 扫描仪无法显示解决方法【详解】...
- TF-tf.keras.layers.Dense
- Collectors.summingLong()
- 【吴恩达深度学习】Residual Networks(PyTorch)
- 征集开始!2022年湖北省人工智能 大数据十大优秀应用案例征集申报时间要求及征集范围、注意事项
- POS机31个基础知识你了解多少?
- 【支付】网络支付-支付网关模式与虚拟账户模式
- 项目日历是什么?如何规划?