WebService introduction

A webService is a programmable URL, an application component that is invoked remotely using standard Http and XML protocols. Webservice consists of three elements:

  1. SOAP: Simple Object Access protocol
  2. UDDI: Universal description discovery integration
  3. WSDL: webservice description language

Here are three of them.

SOAP

Simply put, HTTP+XML=SOAP. The SOAP protocol consists of the following four parts:

  1. SOAP envelop, which defines a framework that describes what a message is, who sent it, who should receive and process it, and how to process it.
  2. SOAP encoding Rules, which define the data types that need to be used when exchanging information between different applications;
  3. SOAP RPC representations (RPC representations), which define a protocol for representing remote procedure calls and responses;
  4. SOAP bindings, which define which underlying protocol SOAP uses to exchange information. HTTP/TCP/UDP can be used.

The message format


      
<soap:Envelope
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
    <soap:Header>
        <! -- Message header, optional -->
    </soap:Header>
    <soap:Body>
        <! -- Message content, required -->

        <soap:Fault>
            <! -- Error message, optional -->
        </soap:Fault>
    </soap:Body>
</soap:Envelope>
Copy the code

A SOAP message is a plain XML document containing the following elements:

  1. The required Envelope element to identify the XML document as a SOAP message;
  2. Optional Header element, containing Header information, commonly used for authentication;
  3. The required Body element, which contains all the call and response information;
  4. An optional Fault element that describes the error that occurred while processing this message;

UDDI

UDDI(Universal Description, Discovery, and Integration) is a directory service that users can use to register and search web services. Some of the types of information used to describe a Web service to help service requesters determine the following questions: WHO,WHAT,WHERE,HOW. UDDI defines HOW to find a Web service (and its WSDL file). UDDI is not as popular as WSDL and SOAP because, in many cases, consumers know the location of Web services (usually within a company’s corporate Intranet). UUDI can be compared to a search engine, which typically returns only the URI of a Web page, whereas a UUID registry returns not only the location of the service, but also how it works.

WSDL

The following focuses on WSDL, considered the most complex of the three. WSDL is essentially an XML-based language for describing Web Services and how they are accessed.

<definitions>
    <types>definition of types........ A container for data type definitions that uses some type system (typically using the type system in XML Schema)</types>
    <message>definition of a message.... Abstract typed definition of the data structure of the communication message. Use the Types defined by Types to define the data structure of the entire message.</message>
    <portType>definition of a port....... An abstract set of operations supported by an access entry point type that can be supported by one or more service access points.</portType>
    <binding>definition of a binding.... Binding of a specific protocol and data format specification for a specific port type.</binding>
    <service>A collection of related service access points.</servie>
</definitions>
Copy the code

The WSDL definition tells you how to access the interface: weather forecast

Return result:

PostMan test

Use Postman to test the weather forecast, a typical WebService service.

  1. Create an HTTP request and fill in the URL addresshttp://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
  2. Add content-type to header:text/xml; charset=utf-8Note The character set must be UTF-8; otherwise, the query result will be empty.

3. Enter the body content, the type is RAW, and the content is as follows:


      
<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>
    <getSupportCity xmlns="http://WebXml.com.cn/">
      <byProvinceName>zhejiang</byProvinceName>
    </getSupportCity>
  </soap:Body>
</soap:Envelope>
Copy the code

The results are as follows: