webservice快速入门-SOAP和WSDL

Web服务快速入门-SOAP和WSDL

什么是SOAP?SOAP:简单对象访问协议

SOAP:简单对象访问协议,简单对象访问协议(SOAP)是一种轻量的、简单的、基于 XML 的协议,它被设计成在 WEB 上交换结构化的和固化的信息。 SOAP 可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议( HTTP),简单邮件传输协议(SMTP),多用途网际邮件扩充协议(MIME)。它还支持从消息系统到远程过程调用(RPC)等大量的应用程序。

说白了,它就是一种基于XML传输数据的协议,为什么基于XML,因为这样可以确保不同平台,语言的通信,也就是经常听到的导构平台之前的通信。

我们常见的json,xml其实都可以理解为是soap的实现。

我们来看一下之前的WSDL文件,访问:http://localhost:7777/tudou?wsdl如下:

[html] view plain copy

  1. This XML file does not appear to have any style information associated with it. The document tree is shown below.
  2. <!--
  3.  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
  4. -->
  5. <!--
  6.  Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
  7. -->
  8. <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.ws.platform.whaty.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://server.ws.platform.whaty.com/" name="MyServiceImplService">
  9. <types>
  10. <xsd:schema>
  11. <xsd:import namespace="http://server.ws.platform.whaty.com/" schemaLocation="http://localhost:7777/tudou?xsd=1"/>
  12. </xsd:schema>
  13. </types>
  14. <message name="minus">
  15. <part name="parameters" element="tns:minus"/>
  16. </message>
  17. <message name="minusResponse">
  18. < part  name = “parameters”  element = “tns:minusResponse” />
  19. </ message >
  20. < message  name = “add” >
  21. < part  name = “parameters”  element = “tns:add” />
  22. </ message >
  23. < message  name = “addResponse” >
  24. < part  name = “parameters”  element = “tns:addResponse” />
  25. </ message >
  26. < portType  name = “IMyservice” >
  27. < 操作 名称 = “减号” >
  28. < input  message = “tns:minus” />
  29. < output  message = “tns:minusResponse” />
  30. </ operation >
  31. < 操作 名称 = “添加” >
  32. < input  message = “tns:add” />
  33. < output  message = “tns:addResponse” />
  34. </ operation >
  35. </ portType >
  36. < binding  name = “MyServiceImplPortBinding”  type = “tns:IMyservice” >
  37. < soap:binding  transport = “http://schemas.xmlsoap.org/soap/http”  style = “document” />
  38. < 操作 名称 = “减号” >
  39. < soap:operation  soapAction = “” />
  40. < input >
  41. < soap:body  use = “literal” />
  42. </ input >
  43. < output >
  44. < soap:body  use = “literal” />
  45. </ output >
  46. </ operation >
  47. < 操作 名称 = “添加” >
  48. < soap:operation  soapAction = “” />
  49. < input >
  50. < soap:body  use = “literal” />
  51. </ input >
  52. < output >
  53. < soap:body  use = “literal” />
  54. </ output >
  55. </ operation >
  56. </ binding >
  57. < 服务 名称 = “MyServiceImplService” >
  58. < port  name = “MyServiceImplPort”  binding = “tns:MyServiceImplPortBinding” >
  59. < soap:address  location = “http:// localhost:7777 / tudou” />
  60. </ port >
  61. </ service >
  62. </ definitions >

我们把节点收起来看得更清楚点:

很清楚的看到这个WSDL分为类型,消息,端口类型,装订,服务这5部分。

类型:用来定义访问的类型,一个类型对应我们服务端接口的一个方法,一个类型对应我们接口的一个返回值我们可以看到上面的WSDL中有一个的schemaLocation =“HTTP://本地主机:7777 /土豆?XSD = 1" 的玩意,我们直接在浏览器访问一下它。

[html]查看纯文本

  1. 这个XML文件似乎没有任何关联的样式信息。文档树如下所示。
  2. <! -
  3.  由JAX-WS RI在http://jax-ws.dev.java.net发布。RI的版本是JDK 6中的JAX-WS RI 2.1.6。 
  4. - >
  5. < xs:schema  xmlns:tns = “http://server.ws.platform.whaty.com/”  xmlns:xs = “http://www.w3.org/2001/XMLSchema”  version = “1.0”  targetNamespace = “http://server.ws.platform.whaty.com/” >
  6. < xs:element  name = “add”  type = “tns:add” />
  7. < xs:element  name = “addResponse”  type = “tns:addResponse” />
  8. < xs:element  name = “minus”  type = “tns:minus” />
  9. < xs:element  name = “minusResponse”  type = “tns:minusResponse” />
  10. < xs:complexType  name = “add” >
  11. < xs:sequence >
  12. < xs:element  name = “arg0”  type = “xs:int” />
  13. < xs:element  name = “arg1”  type = “xs:int” />
  14. </ xs:sequence >
  15. </ xs:complexType >
  16. < xs:complexType  name = “addResponse” >
  17. < xs:sequence >
  18. < xs:element  name = “return”  type = “xs:int” />
  19. </ xs:sequence >
  20. </ xs:complexType >
  21. < xs:complexType  name = “minus” >
  22. < xs:sequence >
  23. < xs:element  name = “arg0”  type = “xs:int” />
  24. < xs:element  name = “arg1”  type = “xs:int” />
  25. </ xs:sequence >
  26. </ xs:complexType >
  27. < xs:complexType  name = “minusResponse” >
  28. < xs:sequence >
  29. < xs:element  name = “return”  type = “xs:int” />
  30. </ xs:sequence >
  31. </ xs:complexType >
  32. </ xs:schema >

看到复杂类型了没有。如果你学了架构和DTD,你就应该知道这实际就是一种类型,下面是相应的子节点,可能还有一些约束。

消息:SOAP,也就是被封装成一个对象的形式,实际上是以XML的形式展现的里面就是传递的我们的数据。

端口类型:就是对应我们的操作了可以看到操作这个单词吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值