Part 1: An intuitive overview
Several concepts of WebService:
Based on the HTTP protocol, a framework/component for client-server communication through XML
Two key points:
1. The functions provided by the server are described through xml
2. The functions described in the first step are embedded in the HTTP protocol, enabling communication through the HTTP protocol [so-called SOAP].
Use pictures It can be represented as follows:
Figure 1: Brief representation of WebService
The main purpose of using these two technologies is:
1. Cross-platform, hosts and servers that support the HTTP protocol can establish communication connections , and most hosts and servers (more than 99.999%) will support the HTTP protocol. Generally speaking, communication between different target hosts needs to go through a firewall and open a certain port. The advantage of the HTTP protocol is that firewalls generally do not block port 80, so that communication can be convenient and safe.
2. Cross-language, any language, supports XML text parsing. The purpose of this is to achieve communication between different languages. The content of communication is restricted by xml, so communication in this way can overcome language barriers. , that is, the server developed in Java, the client can access it with C, it can access it with java, VB, etc., and vice versa.
Part 2: Basic Principles and Architecture
Of course, the architecture is more complicated than the diagram we mentioned above. The above only illustrates the one-to-one communication. The actual situation also needs to consider the following Question, refer to the illustration:
1. The server (Provider) provides unified standardized services. Just like starting a company (i.e. Server Provider), register the company address and nature with the Administration for Industry and Commerce. The purpose is that if others want to use the company's services, they will know your address from the Industrial and Commercial Administration Bureau. Such a unified approach is convenient for all companies and all customers who need the services provided by the company. And this information is disclosed to the maximum extent possible.
2. The client (Requester) goes to the Registration Center (Registry) and gets the basic information of the company, then finds the company and then uses the services provided by the company.
Figure 2: Basic WebService architecture flow chart
Pay attention to the labels of the basic steps in the above figure. The explanation is as follows
1. After the Provider node provides the service, it first registers to the node Registry
2 and 3. The Requester node goes to the Regitry node to check the information and find the required Provider and the Service it provides
4. The Requester uses the services provided by the Provider
For a more specific introduction, refer to the reference [2], the following Basically translated from this reference:
Figure 3: Detailed step flow chart
The above pictures completely present the entire principle process of WebService:
1. Client has needs and wants to call A service, but I don’t know where to call it. But I know it can be found on the UDDI Registry.
2. Sure enough, UDDI records that a server called Web Server A can provide such a service.
3. So Client goes to Web Server A and asks for the exact calling method.
4. After Web Server A sees the "exact method query" proposed by Client, it immediately returns to it an xml document described by WSDL, which records the various method interfaces it can provide.
5. After Client understands this, Encapsulate these xml interface methods into HTTP requests and send them to Web Server A. These encapsulation methods use the standard SOAP method, which is essentially some SOAP message messages that satisfy the HTTP protocol.
6. Web Server A also responds to the SOAP package of the HTTP protocol. In this way, the requests and responses of both parties are completely smooth.
What we see above is the application schematic diagram. Going deeper, we can find the following protocol architecture diagram:
Figure 4: Protocol structure
We have spent a lot of time on it With a lot of energy, it introduces the entire process of discovering Service (UDDI), the interface description provided by Service (WSDL), calling Service (SOAP), and transmission (HTTP). Therefore no introduction will be given. The core of this technology is SOAP.
Part 3: Practicing WebService
Seeing that the above picture is so complicated, in fact, the SOAP+HTTP protocol is mature enough, and there is no need for us to generate SOAP through xml There are many tools that can help us implement changing HTML scripts. In fact, it is quite simple to develop.
Situation A: It is known that Web Service exists, and the client can be developed through the following steps:
1. Through UDDI, find the location of the Web Service required by the Client program
2. Through WebService, find the WSDL interface description file
3. Use the tool to generate a Client Stub from the WSDL file obtained in step 2. This is essentially code, that is, a stub. Merge this stub code into the Client program.
4. Every time the Client needs to call WebService, it directly calls the Stub interface generated in step 4 to realize the call to the Server side.
Situation B: Server-side development also does not need to do such troublesome things as parsing SOAP, the framework will do it for us. The general steps are as follows:
1. Implement all the functions that WebServer needs to provide
2. Use WSDL files (or IDL) to generate Server Stub. These codes will be responsible for receiving requests from the outside world and forwarding them to the Web Server's Service. Implementation (implementation code). When the Service Implementation code is processed and the result is generated, the result will be handed over to the Server Stub, and then the Server Stub can generate a SOAP response. Server Stub + Server Implementation are combined together and are called Web Service Container. This thing is Let HTTP requests sent to WebService be sent directly to Server Stub.
Figure 5: Calls in practical applications
For more WebService introduction, principles, and usage-related articles, please pay attention to the PHP Chinese website!