基于PHP——简单的WSDL的创建(WSDL篇)
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就是对于 传入、传出参数的 名称、类型设置
- <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是对于每一个服务的描述,包括服务接口名称、传入参数、返回值
- <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());
- }
- ?>
详情请查看:
基于PHP——简单的WSDL的创建(WSDL篇)的更多相关文章
- (转)基于PHP——简单的WSDL的创建(WSDL篇)
本文转载自:http://blog.csdn.net/rrr4578/article/details/24451943 1.建立WSDL文件 建立WSDL的工具很多,eclipse.zends ...
- 创建WSDL项目
WSDL文件是测试基于soap的服务,他们定义实际暴露服务和要求SoapUI生成测试,要求信息,验证和MockServices. SoapUI支持最广泛使用的1.1版本的WSDL和SOAP 1.1和1 ...
- soapui中文操作手册(二)----通过您的WSDL请求创建一个测试
1.通过您的WSDL请求创建一个测试 点击加号旁边的导航拓展项目树的Web服务,并选择请求: 在SoapUI Pro中,所述请求编辑出现在右边.SoapUI Pro有一个编辑器,它简化了XML的层 ...
- CountBoard 是一个基于Tkinter简单的,开源的桌面日程倒计时应用
CountBoard 是一个基于Tkinter简单的,开源的桌面日程倒计时应用. 项目地址 https://github.com/Gaoyongxian666/CountBoard 基本功能 置顶功能 ...
- 创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表
创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表 创建数据模型类(POCO类) 在Models文件夹下添 ...
- Tridiv:基于 Web 的 CSS 编辑器,创建炫丽 3D 图形
Tridiv 是一个基于 Web 的编辑器,使用 CSS 创建 3D 形状.它提供了一个传统的四个面板的操作界面,给出了从每个平面的视图,以及一个预览窗格中示出的最终的效果.使用 Tridiv 可以创 ...
- 基于Bootstrap简单实用的tags标签插件
http://www.htmleaf.com/jQuery/ jQuery之家 自由分享jQuery.html5和css3的插件库 基于Bootstrap简单实用的tags标签插件
- Docker 基于已有镜像的容器创建镜像
Docker 基于已有镜像的容器创建镜像: docker:/root# docker run -it januswel/centos /bin/bash docker exec -it januswe ...
- 基于最简单的FFmpeg包封过程:视频和音频分配器启动(demuxer-simple)
===================================================== 基于最简单的FFmpeg封装工艺的系列文章上市: 最简单的基于FFmpeg的封装格式处理:视 ...
随机推荐
- offsetWidth, offsetHeight, offsetLeft, offsetTop,clientWidth, clientHeight,clientX,pageX,screenX
offsetWidth: 元素在水平方向上占用的空间大小.包括元素的宽度,内边距,(可见的)垂直滚动条的宽度,左右边框的宽度. offsetHeight:元素在垂直方向上占用的空间大小,包括元素的高度 ...
- jquery实现调用webservice
1.webservice端 using System; using System.Collections.Generic; using System.Web; using System.Web.Ser ...
- Ubuntu 创建启动器
首先我们要了解,Ubuntu 的 Dash 里所有程序都是在 /usr/share/applications 中的,所以我们的思路很简单——建一个类似于“快捷方式”一样的东西扔进去就好了.所以第一步自 ...
- LINUX下编译安装最新版本mysql
通过参考其他文章 1.下载安装mysql-5.5.30.tar.gz与cmake.2.8.11.2.tar.gz (1)先安装cmake(mysql5.5以后是通过cmake来编译的) [root@ ...
- [Thinkbayes]贝叶斯思维读书笔记-1-贝叶斯定理
使用贝叶斯定理,目前来看最重要的一点在于假设.就是未知事件已知化,同时也要注意假设的全程性,不能从中开始新的假设,这种假设往往是不全面的. 我自己找到的假设的方法有两种,一种是命名,一种是时序.全程性 ...
- idea远程调试linux下的tomcat
要远程调试代码,首先的保障本地的代码和远程tomcat的代码是同一份 首先在本地idea配置一个远程tomcat服务器 host就填写远程主机ip port填写访问的端口(不是调试端口) 然后在Sta ...
- 创建 OVS vlan100 netwrok - 每天5分钟玩转 OpenStack(137)
上一节完成了 OVS vlan network 的配置准备工作,今天我们创建 vlan100.打开菜单 Admin -> Networks,点击 "Create Network&quo ...
- 官网.jar包下载技巧
最近在学Java,但是往往要用到好多jar包,只能从网上下载,但是网上找实在太费事了,而且有时候给我们带来了许多的不便.找不到jar包程序就运行不了,心里真不是个滋味.可是自己就是不甘心.经过我的不懈 ...
- 算法笔记_015:快速排序(Java)
目录 1 问题描述 2 解决方案 2.1 快速排序原理简介 2.2 具体编码 1 问题描述 给定一组数据,使用快速排序得到这组数据的非降序排列. 2 解决方案 2.1 快速排序原理简介 引用自百度百科 ...
- ELK采集之nginx 之高德地图出城市IP分布图
1.采用拓扑: 角色扮演: Agent:采用logstash,IP:192.168.10.7 Redis队列: IP:192.168.10.100 Indexer:logstash,IP:192.16 ...