• ONC RPC协议的问题


    基于 XML 的最著名的通信协议就是 SOAP 了,全称简单对象访问协议(Simple Object Access Protocol)。它使用 XML 编写简单的请求和回复消息,并用 HTTP 协议进行传输。

    SOAP 将请求和回复放在一个信封里面,就像传递一个邮件一样。信封里面的信分抬头和正文。

    1. POST /purchaseOrder HTTP/1.1
    2. Host: www.geektime.com
    3. Content-Type: application/soap+xml; charset=utf-8
    4. Content-Length: nnn
    1. "1.0"?>
    2. <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
    3. soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
    4. <soap:Header>
    5. <m:Trans xmlns:m="http://www.w3schools.com/transaction/"
    6. soap:mustUnderstand="1">1234
    7. m:Trans>
    8. soap:Header>
    9. <soap:Body xmlns:m="http://www.geektime.com/perchaseOrder">
    10. <order>
    11. <date>2018-07-01date>
    12. <className>趣谈网络协议className>
    13. <Author>刘超Author>
    14. <price>68price>
    15. order>
    16. m:purchaseOrder>
    17. soap:Body>
    18. soap:Envelope>

    一种相对比较严谨的 Web 服务描述语言,WSDL(Web Service Description Languages)。它也是一个 XML 文件

    在这个文件中,要定义一个类型 order,与上面的 XML 对应起来。

    1. <wsdl:types>
    2. <xsd:schema targetNamespace="http://www.example.org/geektime">
    3. <xsd:complexType name="order">
    4. <xsd:element name="date" type="xsd:string"></xsd:element>
    5. <xsd:element name="className" type="xsd:string"></xsd:element>
    6. <xsd:element name="Author" type="xsd:string"></xsd:element>
    7. <xsd:element name="price" type="xsd:int"></xsd:element>
    8. </xsd:complexType>
    9. </xsd:schema>
    10. </wsdl:types>

    接下来,需要定义一个 message 的结构。

    1. <wsdl:message name="purchase">
    2. <wsdl:part name="purchaseOrder" element="tns:order"></wsdl:part>
    3. </wsdl:message>

    接下来,应该暴露一个端口。

    1. <wsdl:portType name="PurchaseOrderService">
    2. <wsdl:operation name="purchase">
    3. <wsdl:input message="tns:purchase"></wsdl:input>
    4. <wsdl:output message="......"></wsdl:output>
    5. </wsdl:operation>
    6. </wsdl:portType>

    然后,我们来编写一个 binding,将上面定义的信息绑定到 SOAP 请求的 body 里面。

    1. <wsdl:binding name="purchaseOrderServiceSOAP" type="tns:PurchaseOrderService">
    2. <soap:binding style="rpc"
    3. transport="http://schemas.xmlsoap.org/soap/http" />
    4. <wsdl:operation name="purchase">
    5. <wsdl:input>
    6. <soap:body use="literal" />
    7. </wsdl:input>
    8. <wsdl:output>
    9. <soap:body use="literal" />
    10. </wsdl:output>
    11. </wsdl:operation>
    12. </wsdl:binding>

    最后,我们需要编写 service。

    1. <wsdl:service name="PurchaseOrderServiceImplService">
    2. <wsdl:port binding="tns:purchaseOrderServiceSOAP" name="PurchaseOrderServiceImplPort">
    3. <soap:address location="http://www.geektime.com:8080/purchaseOrder" />
    4. </wsdl:port>
    5. </wsdl:service>

    UDDI(Universal Description, Discovery, and Integration),也即统一描述、发现和集成协议。它其实是一个注册中心,服务提供方可以将上面的 WSDL 描述文件,发布到这个注册中心,注册完毕后,服务使用方可以查找到服务的描述,封装为本地的客户端进行调用。

    此文章为10月Day3学习笔记,内容来源于极客时间《趣谈网络协议》,推荐该课程。

  • 相关阅读:
    VB.net下使用开源免费三维控件Anycad的应用实例分享
    怎么将视频转换成mp4?
    趣学python编程 (二、计算机硬件和用途介绍)
    ASEMI高压二极管CL08-RG210参数,CL08-RG210封装
    Java程序员的MacBookPro(14寸M1)配置备忘录
    C语言进程的相关操作
    闭包——破坏第三方库
    信号处理-卡尔曼滤波
    java学习--day18(TreeSet底层&内部类)
    技术分享|电商数据接口|淘宝天猫京东商品API接口之数据同步
  • 原文地址:https://blog.csdn.net/key_3_feng/article/details/133458167