美文网首页
Webservice初识

Webservice初识

作者: AI数据 | 来源:发表于2018-10-11 23:46 被阅读0次

    Webservice简介

    它是一个软件系统,为了支持跨网络的机器之间相互操作而设计。web service服务通常定义为一组模块化的API,它们可以通过网络进行调用,来执行远程系统的请求服务。
    简单的说:WebService即Web服务,它是一种跨编程语言和跨操作系统平台的远程调用技术。
    web Service:有两大类:

    • 传统的webservice,大web service,相对复杂。
    • 轻量级的webservice
      Web Service采用标准的SOAP协议传输。Web Service采用WSDL作为描述语言,也就是Web Service 的使用说明书。并且W3C为Web Service制定了一套传输数据类型,使用xml进行描述,即XSD(XML Schema Datatypes),任何语言写的web Service 接口在发送数据的时候都要转换成WebService标准的XSD发送。
      常用的服务场景,Webservice客户端向Webservice服务端发送查询请求,服务端在收到请求后解析并访问数据库进行查询,然后包装查询结果返回给客户端。所以Webservice可理解为能提供代理服务的软件系统。

    WebService三要素

    • SOAP (Simple Object Access Protocol):简易对象访问协议,SOAP用来描述传递信息的格式。
    • WSDL (WebServices Description Language):Web服务描述语言,用来描述如何访问具体的接口。
    • UDDI (Universal Description Discovery and Integration):通用描述、发现及整合,用来管理、分发、查询webService。

    SOAP

    它一种简单的基于xml的协议,它使应用程序通过HTTP来交换数据,可以简单的理解为SOAP= http+xml。SOAP协议目前的主流版本为:SOAP1.1和SOAP1.2(soap1.2是被纳入w3c标准后的版本)。为了满足兼容性,客户端会优先使用1.1,服务端采用1.2(同时支持1.1和1.2的客户端)。
    SOAP1.1和SOAP1.2协议的异同 :
    SOAP1.1只可以绑定到HTTP协议,而SOAP1.2除了HTTP协议之外还支持SMTP绑定。在JAX-WS中,类似于大多数框架,SOAP1.1作为默认实现,尽管如此在JAX-WS中可以随时采用SOAP1.2。
    soap协议体包含的元素:
    一条SOAP消息就是一个普通XML文档,包含下列元素:

    • Envelope元素 : 必须,此元素将整个XML文档标识为一个SOAP消息
    • Header元素 : 可选,包含头部消息的XML标签
    • Body元素 : 必须,包含所有的调用和响应的主体信息的标签
    • Fault元素 : 可选,提供有关在处理次消息所发生错误的信息的标签
      完整数据结构 :
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.acdmwebservice.unionflight.com/">
      <soapenv:Header/>
      <soapenv:Body>
            <xmlParam>
              ......
            </xmlParam>
      </soapenv:Body>
      </soapenv:Envelope>
    

    WSDL

    Web服务描述语言,用来描述如何访问具体的接口,w3c中规定

    • < service> 整个webserv的服务视图,它包括了所有的服务端点
    • < binding> 为每个端口定义消息格式和协议细节
    • < portType> 描述webservice可以被执行的操作,以及相关的消息,通过binding指向portType
    • < message> 定义一个操作或者方法的数据参数
    • < types> 定义Webservice使用的全部数据类型

    现实中的服务的wsdl样例

    <wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.acdmwebservice.union.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="QueryDataServiceService" targetNamespace="http://service.acdmwebservice.union.com/">
        <wsdl:types>
            <xs:schema xmlns:tns="http://service.acdmwebservice.union.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://service.acdmwebservice.union.com/" version="1.0">
                <xs:element name="queryData" type="tns:queryData"/>
                <xs:element name="queryDataResponse" type="tns:queryDataResponse"/>
                <xs:complexType name="queryData">
                    <xs:sequence>
                        <xs:element minOccurs="0" name="xmlParam" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
                <xs:complexType name="queryDataResponse">
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:schema>
        </wsdl:types>
        <wsdl:message name="queryData">
            <wsdl:part element="tns:queryData" name="parameters"> </wsdl:part>
        </wsdl:message>
        <wsdl:message name="queryDataResponse">
            <wsdl:part element="tns:queryDataResponse" name="parameters"> </wsdl:part>
        </wsdl:message>
        <wsdl:portType name="QueryDataService">
            <wsdl:operation name="queryData">
                <wsdl:input message="tns:queryData" name="queryData"> </wsdl:input>
                <wsdl:output message="tns:queryDataResponse" name="queryDataResponse"> </wsdl:output>
            </wsdl:operation>
        </wsdl:portType>
        <wsdl:binding name="QueryDataServiceServiceSoapBinding" type="tns:QueryDataService">
            <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
            <wsdl:operation name="queryData">
                <soap:operation soapAction="" style="document"/>
                <wsdl:input name="queryData">
                    <soap:body use="literal"/>
                </wsdl:input>
                <wsdl:output name="queryDataResponse">
                    <soap:body use="literal"/>
                </wsdl:output>
            </wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="QueryDataServiceService">
            <wsdl:port binding="tns:QueryDataServiceServiceSoapBinding" name="QueryDataServicePort">
                <soap:address location="http://10.10.10.10/acdmwebservice/services/queryDataService"/>
            </wsdl:port>
        </wsdl:service>
    </wsdl:definitions>
    
    

    WSDL文档阅读方式:从下往上。拥有服务的wsdl后,就可以供webservice客户端开发使用。

    UDDI

    UDDI是一种目录服务,通过它,企业可注册并搜集Web Service。企业将自己提供的Web Service注册在UDDI,也可以使用别的企业在UDDI注册Web Service服务,从而达到资源共享。UDDI旨在将全球的Web Service资源进行共享。

    参考文献

    相关文章

      网友评论

          本文标题:Webservice初识

          本文链接:https://www.haomeiwen.com/subject/wjziaftx.html