(二)基于PHP——简单的WSDL的创建(WSDL篇)
来源:互联网 发布:ecshop 防止sql注入 编辑:程序博客网 时间:2024/05/16 09:20
转载请注明出处:http://blog.csdn.net/cwt0408/article/details/6952936
(谢谢合作!)
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
<?phpfunction GetPhoneBook($name){$pbook="Zhangsan,13888888888,friend,8888@163.com";return $pbook;}$server = new SoapServer("myphone.wsdl");$server->addFunction("GetPhoneBook");$server->handle (); ?>4、修改client.php
<?phpheader('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
- (二)基于PHP——简单的WSDL的创建(WSDL篇)
- (二)基于PHP——简单的WSDL的创建(WSDL篇)
- 基于PHP——简单的WSDL的创建(WSDL篇)
- (三)基于PHP——复杂的WSDL的创建(WSDL篇)
- (三)基于PHP——复杂的WSDL的创建(WSDL篇)
- (一)基于PHP——WSDL的创建(NON-WSDL篇)
- (一)基于PHP——WSDL的创建(NON-WSDL篇)
- 简单的WSDL的创建(WSDL)-php
- WebService—wsdl的简单介绍(未完)
- WSDL的详解笔记(二)
- Eclipse创建WSDL+AXIS2 (二)
- soap基于契约优先WSDL的开发
- 基于wsdl 文件的webService接口开发
- IOS -- 基于WebService WSDL 的请求
- 基于wsdl的测试数据自动生成技术
- php学习之道:php中soap的使用实例以及生成WSDL文件,提供自动生成WSDL文件的类库——SoapDiscovery.class.php类
- WSDL学习(二)
- WSDL WebService的创建和使用实例
- MYSQL数据库:case when then
- uCOS-II邮箱和消息队列
- winform无法将文件“obj**”复制到“bin**” .
- SimpleDateFormat使用详解(转)
- 硬件基本名词解释
- (二)基于PHP——简单的WSDL的创建(WSDL篇)
- Windows XP+Apache 2.2.4+PHP 5.3.8+MySQL 5.5.17环境配置方法
- 已知经纬度查询Landsat TM 、ETM+ 、MSS 数据的行带 整理版 V1.0
- struts2动态下拉框和复选框取值
- latex斜体
- 9.4递归例题:逆波兰表达式
- HDU 1568 - Fibonacci
- Distributable DB system
- netstat查看linux服务器网络连接状态