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. 请求-响应是最普通的操作类型,不过 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

  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. ?>

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

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

webservice(二)简单实例的更多相关文章

  1. Java WebService 开发简单实例

    Web Service 是一种新的web应用程序分支,他们是自包含.自描述.模块化的应用,可以发布.定位.通过web调用.Web Service可以执行从简单的请求到复杂商务处理的任何功能.一旦部署以 ...

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

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

  3. Java WebService(实战) 简单实例

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

  4. JAVA项目中公布WebService服务——简单实例

    1.在Java项目中公布一个WebService服务: 怎样公布? --JDK1.6中JAX-WS规范定义了怎样公布一个WebService服务. (1)用jdk1.6.0_21以后的版本号公布. ( ...

  5. Webservice入门简单实例

    转载大神 项目目的: 程序A调用程序B中的方法C.. https://blog.csdn.net/lovebosom/article/details/51558139                  ...

  6. 主题:Java WebService 简单实例

    链接地址:主题:Java WebService 简单实例    http://www.iteye.com/topic/1135747 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...

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

    hibernate是非常典型的持久层框架,持久化的思想是非常值得我们学习和研究的.这篇博文,我们主要以实例的形式学习Hibernate,不深究Hibernate的思想和原理,否则,一味追求,苦学思想和 ...

  8. WebService连接winfrom简单实例

    C# 创建.部署和调用WebService的简单示例 webservice 可以用于分布式应用程序之间的交互,和不同程序之间的交互. 具体详细用法可去查询资料.下面开始创建一个简单的webservic ...

  9. phpqrcode生成动态二维码简单实例

    这是一个利用phpqrcode生成动态二维码简单实例,比微信官方提供的接口还要好用.二维码是动态的,不用生成图片,可自定义二维码大小,间隙,跳转地址等. 参数设置: include_once 'php ...

随机推荐

  1. 【转载】COM小结

    原文:http://blog.csdn.net/byxdaz/article/details/6595210 一.Com概念 所谓COM(Componet Object Model,组件对象模型),是 ...

  2. Gitlab+Jenkins学习之路(九)之Jenkins的远程管理和集群

    一.Jenkins的远程管理 Jenkins的远程管理方式包含: Shell ssh SSH Plugin ansible.saltstack (1)Shell ssh在项目构建时,jenkins使用 ...

  3. deque!

    deque:双端队列 比较常用的函数: que.back() 返回容器que的最后一个元素的引用.如果que为空,则该操作未定义. que.begin() 传回迭代器中的第一个数据地址. que.cl ...

  4. Jmeter+ant+jenkins接口自动化测试 平台搭建(三)

    四.报告优化 Jmeter 默认生成报告不是很详细,因此我们需要进行优化.这里我们使用新的报告模板:默认的报告模板是 jmeter-results-detail-report_21.xsl 先上效果图 ...

  5. Jmeter+ant+jenkins接口自动化测试 平台搭建(一)

    平台简介 一个完整的接口自动化测试平台需要支持接口的自动执行,自动生成测试报告,以及持续集成.Jmeter 支持接口的测试,Ant 支持自动构建,而 Jenkins 支持持续集成,所以三者组合在一起可 ...

  6. Vue2.0原理-指令

    指令是 模板解析 的续章,本文会尝试从源码的角度来理解 指令 是如何被提取和应用的. 指令的提取 指令的提取过程是在parse阶段进行的,在 parseHTML 方法中,会解析字符串模板为如下的单个a ...

  7. 详解YUV420数据格式

    原文地址:http://www.cnblogs.com/azraelly/archive/2013/01/01/2841269.html 1. YUV简介 YUV定义:分为三个分量,“Y”表示明亮度( ...

  8. SSO流程

    SSO SSO又名单点登录,用户只需要登录一次就可以访问权限范围内的所有应用子系统.举个简单的例子,你在百度首页登录成功之后,你再访问百度百科.百度知道.百度贴吧等网站也会处于登录状态了,这就是一个单 ...

  9. GitHub笔记(五)——忽略文件、配置别名、搭建服务器

    六.忽略文件 忽略某些文件时,需要编写.gitignore: .gitignore文件本身要放到版本库里,并且可以对.gitignore做版本管理! 忽略文件的原则是: 忽略操作系统自动生成的文件,比 ...

  10. RHEL7 利用双网卡绑定实现VLAN

    使用nmcli创建bond配置 #nmcli connection add type bond ifname bond0 con-name bond0 mode active-backup #nmcl ...