• webServices学习一(了解基础和作用。)


    一、第一部分

      1、         带着几个问题学习:

    l    什么是WebService?

    l    它能做什么?

    l    为什么要学习WebService?

    l    学习WebService要达到什么目的?

    1. 答:WebService,顾名思义就是基于Web的服务。它使用Web(HTTP)方式,接收和响应外部系统的某种请求。从而实现远程调用.
    1. 我们可以调用互联网上查询天气信息Web服务,然后将它嵌入到我们的程序(C/S或B/S程序)当中来,当用户从我们的网点看到天气信息时,他会认为我们为他提供了很多的信息服务,但其实我们什么也没有做,只是简单调用了一下服务器上的一段代码而已
    1. 学习WebService可以将你的服务(一段代码)发布到互联网上让别人去调用,也可以调用别人机器上发布的WebService,就像使用自己的代码一样.。

    l  从WebService的工作模式上理解的话,它跟普通的Web程序(比如ASP、JSP等)并没有本质的区别,都是基于HTTP传输协议的程序。

    l  WebService所使用的数据均是基于XML格式的。目前标准的WebService在数据格式上主要采用SOAP协议。SOAP协议实际上就是一种基于XML编码规范的文本协议。

    第二部:在开始之前必须要让先了解几个名词:

     名词1:  XML. Extensible Markup Language -扩展性标记语言
     
          •XML,用于传输格式化的数据,是Web服务的基础。
     
          •namespace-命名空间。
     
          •xmlns=“http://itcast.cn” 使用默认命名空间。
          
          •xmlns:itcast=“http://itcast.cn”使用指定名称的命名空间。
          
          名词2:WSDL – WebService Description Language – Web服务描述语言。
     
          •通过XML形式说明服务在什么地方-地址。
          
          •通过XML形式说明服务提供什么样的方法 – 如何调用。
          
          l名词3:SOAP-Simple Object Access Protocol(简单对象访问协议)
          
          •SOAP作为一个基于XML语言的协议用于有网上传输数据。
            
          •SOAP = 在HTTP的基础上+XML数据。
          
          •SOAP是基于HTTP的。
          
          •SOAP的组成如下:
          
          •Envelope – 必须的部分。以XML的根元素出现。
          
          •Headers – 可选的。
        
          •Body – 必须的。在body部分,包含要执行的服务器的方法。和发送到服务器的数据。

    一、      WSDL说明:

    <?xml version="1.0" encoding="UTF8" ?>

    <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

      xmlns:tns="http://ws.itcast.cn/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"

      xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.itcast.cn/"

      name="HelloServiceService">

      <types>

      <xsd:schema>

      <xsd:import namespace="http://ws.itcast.cn/"

      schemaLocation="http://localhost:9999/hello?xsd=1" />

      </xsd:schema>

      </types>

      <message name="sayHi">

      <part name="parameters" element="tns:sayHi" />

      </message>

      <message name="sayHiResponse">

      <part name="parameters" element="tns:sayHiResponse" />

      </message>

      <portType name="HelloService">

      <operation name="sayHi">

      <input message="tns:sayHi" />

      <output message="tns:sayHiResponse" />

      </operation>

      </portType>

      <binding name="HelloServicePortBinding" type="tns:HelloService">

      <soap:binding transport="http://schemas.xmlsoap.org/soap/http"

      style="document" />

      <operation name="sayHi">-------- //ws的所提供的方法及服务

      <soap:operation soapAction="" />

      <input>

      <soap:body use="literal" />

      </input>

      <output>

      <soap:body use="literal" />

      </output>

      </operation>

      </binding>

      <service name="HelloServiceService">-------- //ws的名称

      <port name="HelloServicePort" binding="tns:HelloServicePortBinding">

      <soap:address location="http://localhost:9999/hello" />-------- //ws的地址

      </port>

      </service>

    </definitions>

    二、      SOAP说明:

    请求: 

    POST /WebServices/MobileCodeWS.asmx HTTP/1.1

    Host: webservice.webxml.com.cn

    Content-Type: text/xml; charset=utf-8

    Content-Length: length

    SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"  ------因为是在HTTP上发数据,所以必须先遵循HTTP协议

     <?xml version="1.0" encoding="utf-8"?>

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"

         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

      <soap:Body>

        <getMobileCodeInfo xmlns="http://WebXml.com.cn/">

          <mobileCode>string</mobileCode>

          <userID>string</userID>

        </getMobileCodeInfo>

      </soap:Body>

    </soap:Envelope>    

    ------- 1 、XML部分即SOAP协议,必须包含

    --------2 、Envelope元素和Body元素。

    响应:

    HTTP/1.1 200 OK

    Content-Type: text/xml; charset=utf-8

    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

             xmlns:xsd="http://www.w3.org/2001/XMLSchema"

         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

      <soap:Body>

        <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">

          <getMobileCodeInfoResult>string</getMobileCodeInfoResult>

        </getMobileCodeInfoResponse>

      </soap:Body>

    </soap:Envelope>

  • 相关阅读:
    echarts折线图
    利用echarts制作词云
    本周总结
    本周总结
    云服务器项目数据库连接超时问题解决
    iOS下载图片失败
    解决后台json数据返回的字段需要替换的问题
    设置User Agent
    Xcode升级到9.3之后pod问题
    gitLab创建自己的私有库
  • 原文地址:https://www.cnblogs.com/mengyuxin/p/5066072.html
Copyright © 2020-2023  润新知