1、建立WSDL文件      建立WSDL的工具很多,eclipse、zendstudio、vs都可以,我个人建议自己写,熟悉结构,另外自动工具对xml schame类型支持在类型中可能会报错。 下面是我自己写的模板:

  1. <?xml version ='1.0' encoding ='UTF-8' ?>
  2. <definitions name='自定义名称'
  3. targetNamespace='目标命名空间(WSDL所在地址)'
  4. <!--tns自定义目标空间,下面会用到-->
  5. xmlns:tns='目标命名空间(WSDL所在地址)'
  6. xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
  7. xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  8. xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
  9. xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
  10. xmlns='http://schemas.xmlsoap.org/wsdl/'>
  11. <!--<types> 元素定义 web service 使用的数据类型,WSDL 使用 XML Schema 语法来定义数据类型,这里可以定义一些Schema不支持的类型-->
  12. <types>
  13. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  14. targetNamespace="目标命名空间(WSDL所在地址)">
  15. </xsd:schema>
  16. </types>
  17. <!--
  18. 个人理解:message就是对于 传入、传出参数的 名称、类型设置
  19. <message> 元素可定义每个消息的部件,以及相关联的数据类型。
  20. 请求-响应是最普通的操作类型,不过 WSDL 定义了四种类型:
  21. One-way 此操作可接受消息,但不会返回响应。
  22. Request-response    此操作可接受一个请求并会返回一个响应。(常用)
  23. Solicit-response    此操作可发送一个请求,并会等待一个响应。
  24. Notification    此操作可发送一条消息,但不会等待响应。
  25. -->
  26. <message name='请求消息名称(方法名+Request)'>
  27. <part name="term" type="xsd:string"/>
  28. </message>
  29. <message name='响应消息名称(方法名+Response)'>
  30. <part name="value" type="xsd:string"/>
  31. </message>
  32. <!--
  33. 个人理解:portType是对于每一个服务的描述,包括服务接口名称、传入参数、返回值
  34. <portType> 元素是最重要的 WSDL 元素。它可描述一个 web service、可被执行的操作,以及相关的消息。
  35. 它告诉你去哪个WebService的连接点,扮演了一个控制者。
  36. -->
  37. <portType name='执行的操作名称(binding的type与其对应)'>
  38. <operation name='执行操作的方法'>
  39. <input message='tns:*Request'/>
  40. <output message='tns:*response'/>
  41. </operation>
  42. </portType>
  43. <!--<binding> 元素为每个端口定义消息格式和协议细节-->
  44. <binding name='Binding的名称,与service的port名称对应' type='指向用于Binding的端口(tns(前缀):PortType名称)'>
  45. <!--style:属性可取值 "rpc" 或 "document",ransport:属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP-->
  46. <soap:binding style='rpc'
  47. transport='http://schemas.xmlsoap.org/soap/http'/>
  48. <!--operation 元素定义了每个端口提供的操作符,对于每个操作,相应的 SOAP 行为都需要被定义-->
  49. <operation name='GetCallDetailRecords'>
  50. <soap:operation soapAction='http://www.cwtservice.cn/newOperation/'/>
  51. <input>
  52. <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
  53. encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  54. </input>
  55. <output>
  56. <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
  57. encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  58. </output>
  59. </operation>
  60. </binding>
  61. <!--<service>包含一个或者多个port元素,每个port元素表示一个不同的Web服务-->
  62. <service name='服务名称'>
  63. <port name='Binding名称' binding='tns:Binding名称'>
  64. <soap:address location='http://目标命名空间(WSDL所在地址)/service.php'/>
  65. </port>
  66. </service>
  67. </definitions>

2、在service目录下建立myphone.wsdl

  1. <?xml version ='1.0' encoding ='UTF-8' ?>
  2. <definitions name='phonebook'
  3. targetNamespace='http://www.mysoapservice.cn/'
  4. xmlns:tns='http://www.mysoapservice.cn/'
  5. xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
  6. xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  7. xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
  8. xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
  9. xmlns='http://schemas.xmlsoap.org/wsdl/'>
  10. <types>
  11. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  12. targetNamespace="http://www.mysoapservice.cn/">
  13. </xsd:schema>
  14. </types>
  15. <message name='GetPhoneBookRequest'>
  16. <part name="name" type="xsd:string"/>
  17. </message>
  18. <message name='GetPhoneBookResponse'>
  19. <part name="phonebookInfo" type="xsd:string"/>
  20. </message>
  21. <portType name='PhoneBookToEveryOneProt'>
  22. <operation name='GetPhoneBook'>
  23. <input message='tns:GetPhoneBookRequest'/>
  24. <output message='tns:GetPhoneBookResponse'/>
  25. </operation>
  26. </portType>
  27. <binding name='PhoneBookSOAP' type='tns:PhoneBookToEveryOneProt'>
  28. <soap:binding style='rpc'
  29. transport='http://schemas.xmlsoap.org/soap/http'/>
  30. <operation name='GetPhoneBook'>
  31. <soap:operation soapAction='http://www.cwtservice.cn/newOperation/'/>
  32. <input>
  33. <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
  34. encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  35. </input>
  36. <output>
  37. <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
  38. encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  39. </output>
  40. </operation>
  41. </binding>
  42. <service name='PhoneBookService'>
  43. <port name='PhoneBookSOAP' binding='tns:PhoneBookSOAP'>
  44. <soap:address location='http://www.mysoapservice.cn/service.php'/>
  45. </port>
  46. </service>
  47. </definitions>

3、修改service.php

  1. <?php
  2. function GetPhoneBook($name){
  3. $pbook="Zhangsan,13888888888,friend,8888@163.com";
  4. return $pbook;
  5. }
  6. $server = new SoapServer("myphone.wsdl");
  7. $server->addFunction("GetPhoneBook");
  8. $server->handle ();
  9. ?>

4、修改client.php

  1. <?php
  2. header('Content-Type:text/html;charset=utf-8');
  3. $client = new SoapClient("http://www.mysoapservice.cn/service.php?WSDL" , array('trace'=>true));
  4. var_dump($client->__getTypes());
  5. try {
  6. $response = $client->GetPhoneBook('zhang');
  7. var_dump($response);
  8. }catch (SoapFault $sf){
  9. var_dump($sf);
  10. print ($client->__getLastRequest());
  11. print ($client->__getLastResponse());
  12. }
  13. ?>

详情请查看:

基于PHP——简单的WSDL的创建(WSDL篇)

基于PHP——简单的WSDL的创建(WSDL篇)的更多相关文章

  1. (转)基于PHP——简单的WSDL的创建(WSDL篇)

    本文转载自:http://blog.csdn.net/rrr4578/article/details/24451943 1.建立WSDL文件     建立WSDL的工具很多,eclipse.zends ...

  2. 创建WSDL项目

    WSDL文件是测试基于soap的服务,他们定义实际暴露服务和要求SoapUI生成测试,要求信息,验证和MockServices. SoapUI支持最广泛使用的1.1版本的WSDL和SOAP 1.1和1 ...

  3. soapui中文操作手册(二)----通过您的WSDL请求创建一个测试

      1.通过您的WSDL请求创建一个测试 点击加号旁边的导航拓展项目树的Web服务,并选择请求: 在SoapUI Pro中,所述请求编辑出现在右边.SoapUI Pro有一个编辑器,它简化了XML的层 ...

  4. CountBoard 是一个基于Tkinter简单的,开源的桌面日程倒计时应用

    CountBoard 是一个基于Tkinter简单的,开源的桌面日程倒计时应用. 项目地址 https://github.com/Gaoyongxian666/CountBoard 基本功能 置顶功能 ...

  5. 创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表

    创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表 创建数据模型类(POCO类) 在Models文件夹下添 ...

  6. Tridiv:基于 Web 的 CSS 编辑器,创建炫丽 3D 图形

    Tridiv 是一个基于 Web 的编辑器,使用 CSS 创建 3D 形状.它提供了一个传统的四个面板的操作界面,给出了从每个平面的视图,以及一个预览窗格中示出的最终的效果.使用 Tridiv 可以创 ...

  7. 基于Bootstrap简单实用的tags标签插件

    http://www.htmleaf.com/jQuery/ jQuery之家 自由分享jQuery.html5和css3的插件库 基于Bootstrap简单实用的tags标签插件

  8. Docker 基于已有镜像的容器创建镜像

    Docker 基于已有镜像的容器创建镜像: docker:/root# docker run -it januswel/centos /bin/bash docker exec -it januswe ...

  9. 基于最简单的FFmpeg包封过程:视频和音频分配器启动(demuxer-simple)

    ===================================================== 基于最简单的FFmpeg封装工艺的系列文章上市: 最简单的基于FFmpeg的封装格式处理:视 ...

随机推荐

  1. 目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建

    目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建 通过上面的介绍我们知道利用HttpControllerSelector可以根据 ...

  2. CSS样式基础知识

    CSS样式基础知识 CSS样式概述 CSS是Cascading Style Sheet 的缩写.译作“层叠样式表单”.是用于(增强)控制网页样式并允许将样式信息与网页内容分离的一种标记性语言. 引用位 ...

  3. 将SQL获取的信息传递到Email中

    将SQL获取的信息传递到Email中 最近在为公司财务开发一个邮件通知时遇到了一个技术问题.原来我设计SSIS的是每天将ERP系统支付数据导出到财务支付平台后 Email 通知财务,然后财务到支付平台 ...

  4. 【Linux】Shell学习笔记之四——文件和目录管理(硬连接和软连接)

    在这节将要学习linux的连接档,在之前用"ls -l" 查看文件属性的命令时, 其中第二个属性是连接数.那么这个连接数是干什么的?这就要理解inode. 先说一下文件是怎么存储的 ...

  5. php处理金额显示的一些笔记

    最近一直在做关于结算方面的需求,也熟悉了一些处理金额显示的方法,总结如下: 1.每三位数字以逗号分隔,比如1000 => 1,000. 可以直接使用number_format函数.eg:echo ...

  6. snmpwalk高延时问题分析

    问题出现 有两台物理机,一台是192.168.1.15,另一台是192.168.1.43.二者的netsnmp版本相同. 使用snmpwalk去访问两台机器,获取tcp重传数(tcpRetransSe ...

  7. Android本地化资源目录详解

    我们可以设想,有两个不同分辨率的手机(320*480和480*800)要使用一些图像资源,为了使图像不失真,就需要为不同分辨率的手机指定不同的图像,为此就需要建立不同的资源目录. 在res目录中建立了 ...

  8. java获取登陆用户的IP地址

    /** * 通过HttpServletRequest返回IP地址 * @param request HttpServletRequest * @return ip String * @throws E ...

  9. 基于AFNetworking 3.0的取消已发出的网络请求

    一般情况下主动取消请求的需求不会太多 除非以下几种情况 1.比如电商应用为例 请求频繁,数据量大 2.对性能的要求比较高 3.网络环境比较差 当一个用户打开一个界面 看到的却是漫长的等待框 这时候用户 ...

  10. [bzoj2957][楼房重建] (线段树)

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...