WebService-php- 1(16)
最近看了挺多关于php中webservice的资料,感谢燕十八的分享,帮助了我构建服务端的过程。将学习笔记记录如下,其中包含燕十八的笔记。
WebService
1 快速了解WebService
通俗的说:按一定的XML格式,调用远程服务器的方法,且服务器按一定的格式返回XML内容.
"一定的格式"----SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协
议.
远程服务器 ---- 一般通过HTTP协议来传递消息
总结: WebServie == HTTP协议 + Soap格式的XML
例1:soap请求
POST /WebServices/MobileCodeWS.asmx HTTP/1.1
Host: webservice.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: 354
SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://WebXml.com.cn/getMobileCodeInfo >
2 PHP客户端请求WebService
修改PHP.ini
extension=php_soap.dll 前的";"去掉.
并重启apache
PHP SoapClient类可以用来请求WebService
$soap = new soapClient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL');
print_r($soap->getMobileCodeInfo( array('mobileCode'=>'13**********') ) );
Array
(
[] => getMobileCodeInfoResponse getMobileCodeInfo(getMobileCodeInfo $parameters)
[] => getDatabaseInfoResponse getDatabaseInfo(getDatabaseInfo $parameters)
)
Array
(
[] => struct getMobileCodeInfo {
string mobileCode;
string userID;
}
[] => struct getMobileCodeInfoResponse {
string getMobileCodeInfoResult;
}
[] => struct getDatabaseInfo {
}
[] => struct getDatabaseInfoResponse {
ArrayOfString getDatabaseInfoResult;
}
[] => struct ArrayOfString {
string string;
}
// 调用方法
print_r($soap->getMobileCodeInfo( array('mobileCode'=>'') ) );
返回结果
stdClass Object ( [getMobileCodeInfoResult] => 13*********:北京 北京 北京移动动感地带卡 )
3 搭建WebService服务器
wsdl是什么?
wsdl是WebService的规格说明书.
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='自定义名称[可选]'
targetNamespace='命名空间[一般为URL]'
xmlns:tns='命名空间[值同targetNamespace]'
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="[值同上tns]">
</xsd:schema>
</types>
<!--
<message> 元素可定义每个消息的部件,以及相关联的数据类型.
-->
<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='操作列表名'>
<operation name='操作名'>
<input message='tns:操作名Request'/>
<output message='tns:操作名Response'/>
</operation>
</portType>
<!--<binding> 元素为每个端口定义消息格式和协议细节-->
<binding name='WS下的频道名称' type='tns:频道下的操作列表'>
<!--style:属性可取值 "rpc" 或 "document",ransport:属性定义了要使用的 SOAP 协议.在这个例子中我们使用 HTTP-->
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>
<!--operation 元素定义了每个端口提供的操作符,对于每个操作,相应的 SOAP 行为都需要被定义-->
<operation name='test'>
<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='WebService名称[如weatherWS,shopWS]'>
<port name='WS下的频道名称[如cartSoap,购物车服务]' binding='tns:[频道名,同左]'>
<soap:address location='http://[webservice地址]'/>
</port>
</service>
</definitions>
WebService-php- 1(16)的更多相关文章
- RobotFrameWork webservice soap接口测试 (二)
上一篇提到做soap接口测试自己简单的写了个py,然后就简单的实现了个客户端能对远程接口进行调用,对返回的数据进行解析,可后面想着也觉得不对劲,soap协议虽说不像http协议那么普及,但是现在很多公 ...
- 简述WebService的使用(二)
上集回顾 上一篇我简单的介绍了一下整个WebService建立和后端访问的过程,如果感兴趣可以看一看:简述WebService的使用(一) //如有不懂请留言,觉得有用请点赞 内容提要 这一篇主要介绍 ...
- Web 在线文件管理器学习笔记与总结(15)剪切文件夹 (16)删除文件夹
(15)剪切文件夹 ① 通过rename($oldname,$newname) 函数实现剪切文件夹的操作 ② 需要检测目标文件夹是否存在,如果存在还要检测目标目录中是否存在同名文件夹,如果不存在则剪切 ...
- Windows Phone开发(16):样式和控件模板
原文:Windows Phone开发(16):样式和控件模板 在前面资源一文中也提过样式,样式就如同我们做HTML页排版时常用到的CSS样式表,它是对于特定娄型的可视化元素,应该可以直接说是针对控件的 ...
- Java设计模式(16)中介模式(Mediator模式)
Mediator定义:用一个中介对象来封装一系列关于对象交互行为. 为何使用Mediator模式/中介模式 各个对象之间的交互操作非常多,每个对象的行为操作都依赖彼此对方,修改一个对象的行为,同时会涉 ...
- leecode刷题(16)-- 字符串转换整数
leecode刷题(16)-- 字符串转换整数 字符串转换整数 描述: 请你来实现一个 atoi 函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格 ...
- Qt 学习之路 2(16):深入 Qt5 信号槽新语法
Qt 学习之路 2(16):深入 Qt5 信号槽新语法 豆子 2012年9月19日 Qt 学习之路 2 53条评论 在前面的章节(信号槽和自定义信号槽)中,我们详细介绍了有关 Qt 5 的信号 ...
- RocketMQ学习笔记(16)----RocketMQ搭建双主双从(异步复制)集群
1. 修改RocketMQ默认启动端口 由于只有两台机器,部署双主双从需要四个节点,所以只能修改rocketmq的默认启动端口,从官网下载rocketmq的source文件,解压后使用idea打开,全 ...
- Flutter学习笔记(16)--Scaffold脚手架、AppBar组件、BottomNavigationBar组件
如需转载,请注明出处:Flutter学习笔记(15)--MaterialApp应用组件及routes路由详解 今天的内容是Scaffold脚手架.AppBar组件.BottomNavigationBa ...
- 【雕爷学编程】Arduino动手做(16)---数字触摸传感器
37款传感器和模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器与模块,依照实践出真知(动手试试)的理念,以学习和交流为目的,这里准备 ...
随机推荐
- 图片拼接SIFT
图片拼接 SIFT: 特征点处理:位置插值,去除低对比度点,去除边缘点 方向估计 描述子提取 下面的程序中使用: 第一步: 使用SIFT生成器提取描述子和特征 第二步: 使用KNN检测来自A,B图的S ...
- 单独运行shell脚本与crontab运行shell脚本的区别
crontab运行脚本存在两大问题:环境变量和路径,从而导致单独运行脚本没问题,但用crontab运行就报错. 1.环境变量 描述问题:crontab: usage error: no argumen ...
- 127. Word Ladder (Tree, Queue; WFS)
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...
- Oracle 注意点大全
1.索引 经常查询的字段.主表与从表关联主键id必须建立索引.
- animate.css动画种类
animate.css 一个非常好用的css动画库 Github地址 包括了一下多种动画 1. bounce 弹跳 2. flash 闪烁 3. pulse 放大,缩小 4. rubberBand 放 ...
- How to use mouse to moving windows of not have title bar?
How to use mouse to moving windows of not have title bar? #include "widget.h" #include < ...
- Linux select/poll和epoll实现机制对比
关于这个话题,网上已经介绍的比较多,这里只是以流程图形式做一个简单明了的对比,方便区分. 一.select/poll实现机制 特点: 1.select/poll每次都需要重复传递全部的监听fd进来,涉 ...
- winnfsd 操作
# 查看服务端输出了哪些目录,如何挂载 vagrant@homestead:~$ showmount -e 192.168.10.1 Export list for 192.168.10.1: /C/ ...
- oj 1002题 (大数题)
#include <stdio.h> #include <string.h> int main(void) { int q,j,h,k,l; int d; ],s2[];//题 ...
- 前端福利之个性化设置table的td宽度(总结)
很多时候,我们在用到table时,都希望随意设置 每个单元格的宽度,而不希望单元格被内容撑开table的样式. 1.首先,设置table的宽度 width=“1000” 或者 width=“100%” ...