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

[html] view plaincopy
  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. 请求-响应是最普通的操作类型,不过 WSDL 定义了四种类型:
  20. One-way 此操作可接受消息,但不会返回响应。
  21. Request-response    此操作可接受一个请求并会返回一个响应。(常用)
  22. Solicit-response    此操作可发送一个请求,并会等待一个响应。
  23. Notification    此操作可发送一条消息,但不会等待响应。
  24. -->
  25. <message name='请求消息名称(方法名+Request)'>
  26. <part name="term" type="xsd:string"/>
  27. </message>
  28. <message name='响应消息名称(方法名+Response)'>
  29. <part name="value" type="xsd:string"/>
  30. </message>
  31. <!--
  32. <portType> 元素是最重要的 WSDL 元素。它可描述一个 web service、可被执行的操作,以及相关的消息。
  33. 它告诉你去哪个WebService的连接点,扮演了一个控制者。
  34. -->
  35. <portType name='执行的操作名称(binding的type与其对应)'>
  36. <operation name='执行操作的方法'>
  37. <input message='tns:*Request'/>
  38. <output message='tns:*response'/>
  39. </operation>
  40. </portType>
  41. <!--<binding> 元素为每个端口定义消息格式和协议细节-->
  42. <binding name='Binding的名称,与service的port名称对应' type='指向用于Binding的端口(tns(前缀):PortType名称)'>
  43. <!--style:属性可取值 "rpc" 或 "document",ransport:属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP-->
  44. <soap:binding style='rpc'
  45. transport='http://schemas.xmlsoap.org/soap/http'/>
  46. <!--operation 元素定义了每个端口提供的操作符,对于每个操作,相应的 SOAP 行为都需要被定义-->
  47. <operation name='GetCallDetailRecords'>
  48. <soap:operation soapAction='http://www.cwtservice.cn/newOperation/'/>
  49. <input>
  50. <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
  51. encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  52. </input>
  53. <output>
  54. <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
  55. encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  56. </output>
  57. </operation>
  58. </binding>
  59. <!--<service>包含一个或者多个port元素,每个port元素表示一个不同的Web服务-->
  60. <service name='服务名称'>
  61. <port name='Binding名称' binding='tns:Binding名称'>
  62. <soap:address location='http://目标命名空间(WSDL所在地址)/service.php'/>
  63. </port>
  64. </service>
  65. </definitions>

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

[html] view plaincopy
  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

[html] view plaincopy
  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

[html] view plaincopy
  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. ?>

测试:
http://www.mysoapclient.cn/client.php

转载:http://blog.csdn.net/cwt0408/article/details/6952936

转载于:https://www.cnblogs.com/yuwensong/p/4387163.html

webservice(二)简单实例相关推荐

  1. webservice实例java_Java WebService(实战) 简单实例

    一.准备工作(以下为本实例使用工具) 1.MyEclipse10.7.1 2.JDK 1.6.0_22 二.创建服务端 1.创建[Web Service Project],命名为[TheService ...

  2. vue 调用webservice_js跨域调用WebService的简单实例

    步骤1. 在web.config中的system.web节点里加入 步骤2.webservice代码 using System; using System.Collections.Generic; u ...

  3. 用Java 开发 WebService Axis简单实例

    用 Java 开发 WebService Axis 简单实例 在开发之前, 先了解一下AXIS,axis目前出现的2版本以其灵活性,快速开发工具的集成高于xfire而使用者居其上.用Eclipse开发 ...

  4. java开发webservice简单实例_jsp实现的webservice的简单实例

    jsp webservice用到的比较少但是用到就是一个大东西了经常用过其它的api形式了而webservice用到不多,下面我们来看一篇关于jsp实现的webservice的简单实例吧,具体如下. ...

  5. 使用CXF发布WebService服务简单实例

    一.说明: 前面介绍了使用axis2来发布Webservice服务,现在介绍一种更popular,更高效的Webservice服务发布技术:CXF Apache CXF = Celtix + XFir ...

  6. php使用webservivce_使用zeng studio 创建的php调用webservice soap简单实例

    这两天一直在研究webservice soap是个什么东西,究竟怎么创建webservice,又如何用php调用webservice的借口,经过奋战,终于总算弄懂一点的.然后我做了一个webservi ...

  7. 关于webservice的异步调用简单实例

    于webservice的异步调用简单实例 无论在任何情况下,被调用方的代码无论是被异步调用还是同步调用的情况下,被调用方的代码都是一样的, 下面,我们就以异步调用一个webservice 为例作说明. ...

  8. Hibernate搭建开发环境+简单实例(二)

    2019独角兽企业重金招聘Python工程师标准>>> Hibernate是非常典型的持久层框架,持久化的思想是非常值得我们学习和研究的.这篇博文,我们主要以实例的形式学习Hiber ...

  9. php 二位数组随机,PHP多维数组 php打乱数组二维数组多维数组的简单实例

    php中的shuffle函数只能打乱一维数组,有什么办法快速便捷的打乱多维数组?手册上提供了 上面这个是针对二维数组的! 下面针对多维数组的乱序方法?尽可能的方便快速: 以下函数也是出自php手册,可 ...

最新文章

  1. Yii使用CTreeView树
  2. 同时删除两张表的数据_把数据表中对应工作表的数据首先删除,然后导入数据...
  3. 好程序员Web前端教程分享JavaScript开发技巧
  4. postgresql 创建用户_国内源安装postgresql
  5. java home not set_Error: JAVA_HOME is not set and could not be found.
  6. LeetCode - 3Sum Closest
  7. Java:如何创建轻量级数据库微服务
  8. CodeForces - 1144F搜索+简单图论
  9. 私钥公钥学习心得(二)比特币与支付宝
  10. Spring Validation校验
  11. 设置mysql acquisition_MYSQL 7*24 高可用环境的部署
  12. Java 实现线性运动界面_java 实现顺序结构线性列表
  13. 扫描仪twain驱动是什么_扫描仪无法显示怎么办 扫描仪无法显示解决方法【详解】...
  14. TF-tf.keras.layers.Dense
  15. Collectors.summingLong()
  16. 【吴恩达深度学习】Residual Networks(PyTorch)
  17. 征集开始!2022年湖北省人工智能 大数据十大优秀应用案例征集申报时间要求及征集范围、注意事项
  18. POS机31个基础知识你了解多少?
  19. 【支付】网络支付-支付网关模式与虚拟账户模式
  20. 项目日历是什么?如何规划?

热门文章

  1. NYOJ 30 Gone Fishing JAVA+解析
  2. 中蒙最大陆路口岸2018年运行中欧班列1052列
  3. C语言博客作业--函数嵌套调用
  4. SharePoint 2013中规划企业搜索体系结构
  5. monkey自定义脚本实践
  6. ECMAScript6入门--Class对象
  7. 激励理论在人力资源管理中的运用
  8. Ansible9:条件语句【转】
  9. iOS 之 tableView的复用、设计模式
  10. ExtJS FormPanel不执行校验