SOAP在PHP中的使用
来源:互联网 发布:怎么咨询网络服务商 编辑:程序博客网 时间:2024/05/22 14:55
SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协议,它包括四个部分:SOAP封装(envelop),封装定义了一个描述消息中的内容是什么,是谁发送的,谁应当接受并处理它以及如何处理它们的框架;SOAP编码规则(encoding rules),用于表示应用程序需要使用的数据类型的实例; SOAP RPC表示(RPC representation),表示远程过程调用和应答的协定;SOAP绑定(binding),使用底层协议交换信息。
WSDL(Web Service Description Language)就是描述XML Web服务的标准XML格式,WSDL由Ariba、Intel、IBM和微软等开发商提出。它用一种和具体语言无关的抽象方式定义了给定Web服务收发的有关操作和消息。就其定义来说,你还不能把WSDL当作一种对象接口定义语言,例如,CORBA或COM等应用程序体系结构就会用到对象接口定义语言。 WSDL保持协议中立,但它确实内建了绑定SOAP的支持,从而同SOAP建立了不可分割的联系。所以,当我在这篇文章中讨论WSDL的时候,我会假定你把SOAP作为了你的通讯协议。
SOAP和WSDL虽然是web service的两大标准,但是两者并没有必然的联系,都可以独立使用。它们之间的关系就类似HTTP和Html之间的关系。前者是一种协议,后者是对一个Web Server的描述。
一 客户端
通过调用SoaPClient对象可以获取到被调用的对象
header("content-type:text/html;charset=utf-8");try { $client = new \SoapClient("http://***.******.com/services/AcceptedBusiness?wsdl"); print_r($client->__getFunctions()); print_r($client->__getTypes()); } catch (SOAPFault $e) { print $e;}$return = $client->insertProduct(...);二 服务器端
服务器端实际上就是生成xml文件,其中有可调用的方法以及参数.
以Zend为例
$autodiscover = new \Zend\Soap\AutoDiscover();$soapClass = $this->getServiceLocator()->get($soapClassName);$autodiscover->setClass($soapClass)->setUri($url)->setComplexTypeStrategy(new OptionalArrayTypeSequence());header('Content-type: text/xml');echo $autodiscover->toXml();通过此步生成xml文件其中SoapClassName为一个类,定义了多个方法
class Product{ public function insertProduct($products) { ...... }}如此客户端可以直接调用方法 insertProduct生成的XML类似:
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:typens="urn:test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="test" targetNamespace="urn:test"> <wsdl:types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:test"> <xsd:complexType name="productInfoEntity"> <xsd:sequence> <xsd:element name="sku" type="xsd:string" /> <xsd:element name="title" type="xsd:string" /> <xsd:element name="price" type="xsd:string" /> <xsd:element name="size" type="xsd:string" /> <xsd:element name="description" type="xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="productsEntity"> <xsd:sequence> <xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray" type="typens:productInfoEntity"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="productExportEntity"> <xsd:sequence> <xsd:element name="result" type="xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:element name="productRequestParam"> <xsd:complexType> <xsd:sequence> <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" /> <xsd:element minOccurs="1" maxOccurs="1" name="content" type="typens:productsEntity" /> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="productResponseParam"> <xsd:complexType> <xsd:sequence> <xsd:element minOccurs="1" maxOccurs="1" name="result" type="typens:productExportEntity" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> <wsdl:message name="productRequest"> <wsdl:part name="parameters" element="typens:productRequestParam" /> </wsdl:message> <wsdl:message name="productResponse"> <wsdl:part name="parameters" element="typens:productResponseParam" /> </wsdl:message> <wsdl:portType name="productPortType"> <wsdl:operation name="product"> <wsdl:documentation>Update product</wsdl:documentation> <wsdl:input message="typens:productRequest" /> <wsdl:output message="typens:productResponse" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="productBinding" type="typens:productPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="product"> <soap:operation soapAction="" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="testService"> <wsdl:port name="productPort" binding="typens:productBinding"> <soap:address location="http://...." /> </wsdl:port> </wsdl:service></wsdl:definitions>
- SOAP在PHP中的使用
- 【soap】php中使用soap
- PHP使用SOAP
- PHP SOAP 使用示例
- php soap 使用实例
- php soap的使用
- php soap 使用
- PHP的soap使用
- PHP 中使用 SOAP
- PHP 使用soap
- 发现一个比SOAP,RPC等更爽的工具hessian 及在PHP中的使用介绍
- 在 PHP 中使用 SOAP 协议调用 Web服务(WebService)
- PHP使用SOAP做webservice
- PHP 中使用 SOAP(1)
- PHP 中使用 SOAP(2)
- PHP 中使用 SOAP(1)
- PHP 中使用 SOAP(2)
- PHP 使用soap有两种方式。
- linux批量管理推送工具mussh和pssh介绍
- hdu 6082 度度熊与邪恶大魔王(完全背包)
- nRF52832 — DFU升级
- Greenplum 临时表年龄问题
- 风口的猪-中国牛市(动态规划)
- SOAP在PHP中的使用
- 仿ios侧滑推出当前界面
- javascript常用类型数值比较图
- 架构师---(大型网站技术架构核心原理与案例分析)2网站架构模式
- Mysql高级查询语句练习
- 轻松把玩HttpClient之配置ssl,采用绕过证书验证实现https
- Linux-视频监控系统(9)-移植到树莓派中的计划
- mysql 对查询为null的值赋默认值
- Win10 开启移动热点 WiFi 的简单方法