Concept and working principle of WebService (I). Working Principle of webservice

Source: Internet
Author: User
Tags soap client stock prices

Concept and working principle of WebService (I). Working Principle of webservice

Today, let's learn about WebService. What is it?

Web service is a platform-independent, low-coupling, self-contained, programmable web-based application that can use open XML (a subset of standard General Markup Language) standards are used to describe, publish, discover, coordinate, and configure these applications for Distributed interoperability applications.

I. Basic concepts of Web Service

Web Service, also known as XML Web Service WebService, is a lightweight independent communication technology that can receive requests from other systems on the Internet or Intranet. Yes: The software services provided on the Web through SOAP are described using the WSDL file and registered through UDDI.

XML :( Extensible Markup Language) Extended Markup Language. Short-term-oriented temporary data processing and hichina network are the basis of Soap.

Soap: (Simple Object Access Protocol) Simple Object Access Protocol.

Is the communication protocol of XML Web Service. After you find your WSDL Description document through UDDI, you can use SOAP to call one or more operations in your Web service. SOAP is a standard for calling methods in XML format. It supports different underlying interfaces, such as HTTP (S) or SMTP.

Speaking of Web Services, it is difficult to separate it from SOAP. SOAP is a lightweight protocol used to exchange XML encoding information. It has three main aspects: XML-envelope defines the framework for describing information content and how to process content;
Rules for encoding program objects into XML objects;
Execute the Remote Procedure Call (RPC) Convention. SOAP can run on any other transmission protocol.For example, SMTP has different headers in the transport layer, but the XML payload remains the same. On the surface, the XML-based mode should be slower than the binary-based mode, but it is not as simple as the surface. First, when SOAP is used to send messages over the Internet, the time for encoding/decoding messages from each endpoint is insignificant compared with the time for transmitting bytes between the endpoints, therefore, using XML is not a big problem in this case. Web Service Definition Language (WSDL)

WSDL :( Web Services Description Language) the WSDL file is an XML document that describes a group of SOAP messages and how to exchange them. In most cases, it is automatically generated and used by the software.

WSDL is an XML Application that defines the Web service description as a set of service access points, the client can use these service access points to access services that contain document information or process calls (similar to remote process calls ). WSDL first abstracts the access operations and the request/response messages used for access, then, bind it to the specific transmission protocol and Message format to finally define the service access point for specific deployment. The Service Access Points of specific deployment become abstract Web services through combination.

 

In specific use, we can extend the WSDL (similar to the scalability of SOAP), regardless of the Message format or network protocol used for communication, you can describe the Service Access Point and the message format used. In the WSDL framework, any message format and network protocol can be used, just as any network protocol can be used in SOAP. The WSDL Specification defines how to use the SOAP message format, http get/POST message format, and MIME format to complete Web service interaction.

The WSDL document uses the following elements in the Web service definition:

Service uses a special binding, which is an implementation of portType. PortType defines the operation, and the operation is composed of messages. The message contains the XML defined in the types section.

1. types-custom data Types other than the data Types defined in XML Schema used in Web services are defined. For our custom classes (Book), a <complexType>, the <element> element is used to specify the type of each parameter.

2. the JAX-RPC specification specifies the ing of the Data Type of the Java language to the XML Schema data type, such as int <-> xsd: int, java. lang. string <-> xsd: string and so on, as well as the array ing method.

3. message-specifically defines the data structure of the Message used in communication. The Message element contains a group of Part elements, and each Part element is an integral Part of the final Message, each Part references a ype to represent its structure. For example, if the addBook () method has a Book-type parameter, the description of <part name = "book" type = "tns1: Book"/> is displayed in the WSDL.

4. Operation-an abstract description of the operations supported in the service. Generally, a single Operation describes the request/Response Message pair of an access entry.

5. PortType-PortType defines a type of service access entry. What is the type of access entry? The mode and format of the incoming/outgoing message. A PortType can contain several operations, while an Operation is a type of call supported by the access portal. In WSDL, four access entry call modes are supported:

    1. Single request;
    2. Single response;
    3. Request/response;
    4. Response/request.

    Requests refer to requests from the client to the Web server, and responses refer to requests from the Web server to the client. One or two messages in the message definition section are referenced in the PortType definition as the format of the request or response message. For example, an access entry to a stock query may support two types of request messages. One request message indicates the stock code, and the other request message indicates the stock name, the response message may be the stock price.

  • Let's take a look at a WSDL document. Generally, we should first look for the <portType> element to see which methods are used in the Web service represented by this WSDL, and what their parameters and return values are. These methods are represented by <operation> elements in <portType>. <operation> <input> and <output> sub-elements can be included to represent the input and output of methods. Note that the method can only be input or output.

  • Binding-contains how to convert the abstract interface element (portType) to the details of specific representation, that is, the combination of specific data formats and protocols; binding of specific protocols and data format specifications for specific port types. The JAX-RPC specification specifies that SOAP binding can have rpc and document types, indicating Remote Procedure Calls and message-based methods, respectively. The use attribute can be encoded or literal. For the former, rpc is supported, and for the latter, rpc and document are supported.

  • Port-defines a single service access point that combines protocol/Data Format binding with a specific Web access address.

  • Service-Describe the deployment details of all access portals provided by a specific deployed Web Service. A service usually contains multiple Service access portals, each access entry uses a Port element for description.

  • Port describes the deployment details of a service access portal, including the Web address (URL) used for access and the message call mode used for access. The message call mode is represented by the Binding structure. The Binding structure defines that a PortType is bound to a specific network transmission protocol or message transmission protocol. At this level, the content described is related to the deployment of a specific service. For example, you can bind PortType to SOAP/HTTP or MIME/SMTP.

  • PortType (combined with the message and type elements) describes what a Web service is, binding describes how to use a Web service, and port and service describes the location of a Web service.

  • After introducing the main elements of WSDL, we will find that the design concept of WSDL fully inherits the consistent design concept of XML-based contemporary Web technology standards: openness. WSDL allows you to use other types of definition languages (not just XML Schema) by extension, and supports multiple network transmission protocols and message formats (not just those defined in specifications: SOAP/HTTP, HTTP-GET/POST and MIME ).

UDDI (Universal Description, Discovery, and Integration)

Is a new project mainly targeting Web service providers and users. Before you can call a Web service, you must determine the business methods contained in the service, find the called interface definition, and compile software on the server, UDDI is a mechanism that guides the system to find the corresponding service based on the description document. UDDI uses the SOAP message mechanism (standard XML/HTTP) to publish, edit, browse, and find registration information. It uses XML format to encapsulate different types of data and sends the data to the Registration Center or the Registration Center to return the required data.

Ii. Call Principle

Web services have two meanings: 1. It refers to a collection of functions encapsulated into a single entity and released to the network; 2. It refers to the services provided after the collection of functions is called. Simply put, a Web Service is a URL resource. A client can request its services through programming without knowing how the requested service is implemented, this is different from the traditional Distributed Component Object Model.

The architecture of Web services is based on three roles: Web service provider, Web service requestor, and Web service intermediary and three actions: release, discovery, and binding. Simply put, a Web service provider is the owner of a Web Service. It patiently waits for other services and users to provide their existing functions. A Web service requestor is the user of a Web service function, it uses SOAP messages to send requests to Web service providers to obtain services. Web service intermediaries associate a Web service requestor with a suitable Web service provider, it acts as a manager, typically UDDI. These three roles are divided according to the logical relationship. In actual applications, there may be overlapping roles: A Web service can be a Web service provider, it can also be a Web service requestor or both. Shows the relationship between Web service roles. "publish" is used to let users or other services know the existence and related information of a Web service. "Search (discover) "is to find the appropriate Web service;" binding "is to establish a certain relationship between the provider and the requester.

The system diagram below is carefully drawn by me. I can understand it at a glance .....

To implement a complete Web Service, follow these steps:

◆ Web service providers design and implement Web services, publish the Web services that have been correctly debugged through Web service intermediaries, and register them in the UDDI registration center; (publish)

◆ The Web service requestor requests a specific service from the Web service intermediary. The intermediary queries the UDDI registration center based on the request to find the service that satisfies the request for the requester. (discovery)

◆ The Web service intermediary returns the qualified Web service description to the Web service requestor. The description is written in WSDL and can be read by various machines that support Web services. (discovery)

◆ Use the description returned by the Web service intermediary to generate the corresponding SOAP message and send it to the Web service provider for Web service calling. (binding)

◆ The Web service provider executes the corresponding Web service based on the SOAP message and returns the service result to the Web service requestor. (BIND)

Iii. Web Service Features

The main goal of Web Service is cross-platform interoperability. To achieve this goal, Web services are fully based on standards independent of the platform and software vendors, such as XML (Extensible Markup Language) and XSD (XML Schema, is a new platform for creating interoperable and distributed applications. Therefore, using Web Service has many advantages:

1. Cross-firewall communication

If the application has thousands of users distributed all over the world, communication between the client and the server will be a tough problem. Because there is usually a firewall or proxy server between the client and the server. The traditional approach is to use a browser as the client, write a lot of ASP pages, and expose the middle layer of the application to the end user. The result is that development is difficult and programs are difficult to maintain. If the client code is no longer so dependent on HTML forms, the client programming will be much simpler. If the intermediate layer component is changed to Web Service, you can directly call the intermediate layer component from the user interface, thus saving the step for creating an ASP page. To call a Web Service, you can directly use a SOAP client such as Microsoft SOAP Toolkit or. net, or use a self-developed SOAP client to connect it to the application. This not only shortens the development cycle, but also reduces Code complexity and enhances the maintainability of applications. At the same time, the application does not need to jump to the corresponding "result page" every time it calls the middle layer components ".

2. Application Integration

Enterprise-level application developers know that enterprises often need to integrate various programs written in different languages and run on different platforms, this integration will take a lot of development effort. Applications often need to obtain data from programs on a running host, or send data to the host or other platform applications. Even on the same platform, various software products produced by different software vendors often need to be integrated. Through Web Service, applications can use standard methods to "expose" functions and data for other applications.

XML Web services provides the ability to exchange messages using standard protocols (HTTP, XML, SOAP, and WSDL) in a loosely coupled environment. Messages can be structured, typed, or loosely defined.

3. B2B Integration

B2B refers to Business, as in businesses doing business with other businesses, the e-commerce of merchants (generally referred to as enterprises, that is, products, services, and information exchange between enterprises over the Internet. The popular saying means that both the supply and demand sides of e-commerce transactions are merchants (or enterprises or companies). They use Internet technology or various business network platforms to complete the business transaction process.

Web Service is the key to successful B2B integration. With Web Service, the company only needs to expose key business applications to specified suppliers and customers, and the Web Service runs on the Internet, it can be easily implemented anywhere in the world, and its operation cost is relatively low. Web Service is only a key part of B2B integration, and many other parts are required for integration. The biggest benefit of implementing B2B integration with Web services is that it can easily implement interoperability. As long as the business logic is exposed and becomes a Web Service, any designated partner can call these business logic, regardless of the platform on which their system runs, the development language used. This greatly reduces the time and cost spent on B2B integration.

4. software and data Reuse

Web Service allows code reuse while reusing the data behind the code. When using Web Services, you no longer have to purchase and install software components from a third party, as before, and then call these components from the application; you only need to directly call the remote Web Service. Another case of software reuse is to integrate the functions of several applications and expose them through Web Services, you can easily integrate all these functions into your portal to provide users with a unified and friendly interface. You can use the functions provided by third-party Web services in applications, or provide your own application functions to others through Web Services. In both cases, you can reuse the data behind the code and code.

Iv. disadvantages of Web Service

1. standalone applications

Currently, enterprises and individuals still use many desktop applications. Some of them only need to communicate with other programs on the local machine. In this case, it is best not to use Web services, as long as you use local APIs. COM is very suitable for working in this case because it is small and fast. The same is true for the software running on the same server. Of course, Web services can also be used in these scenarios, but that will not only consume too much, but will not bring any benefits.

2. Lan applications

In many applications, all programs use COM on the Windows platform and run on the same LAN. In these programs, using DCOM is much more effective than SOAP/HTTP. Similarly, if A. net Program is to connect to another. net program on the LAN, it should use. net Remoting. In fact, in. net Remoting, you can also specify the use of SOAP/HTTP for Web Service calls. However, it is better to call RPC directly through TCP, which will be much more effective.

1.3 XML Web Service applications

1. The original XML Web Service is usually a source of information that can be easily incorporated into applications, such as stock prices, weather forecasts, and sports scores.

2. Provide existing applications in XML Web Service Mode, build new and more powerful applications, and use XML Web Service as the construction block.

For example, a user can develop a purchase application to automatically obtain price information from different suppliers, so that the user can select a supplier, submit an order, and then track the transportation of the goods until the goods are received. In addition to providing services on the Web, supplier applications can also use XML Web Service to check the customer's credit, collect the payment, and handle the freight formalities with the freight company.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.