Talking about and actually fighting Web Service

zhaozj2021-02-12  161

Briefly introduce SOA and individuals' understanding of WebService. In addition to a specific project introduction, some need to pay attention to problems

Quote article: (1) http://webservices.xml.com/pub/a/ws/2003/09/30/soa.html (2) ms-help: //ms.vscc.2003/ms.msdnqtr. 2003FEB.2052 / cpguide / html / cpconanatomyofsoapwebservicelifetime.htm (3) ms- help: //MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconcustomizingsoapinaspnetwebserviceswebserviceclients.htm

"The words said that the world is big, the long-lasting must be combined, and the long-lasting must be divided." (Romance of the Three Kingdoms) ---- The software industry is not the same?

The current software industry has a variety of technical platforms, architectures, but due to different views of different platforms, each characteristic, there is difficult to communicate between platforms, thereby forming an information from one by island. So how do you link these information is island? The industry puts forward a lot of programs, a very famous solution is Serviced-Oriented (service-oriented). What is the service? This is the definition of it: "SOA IS an architectural style whose goal is to achieve loose coupling among interacting software agents. A service is a unit of work done by a service provider to achieve desired end results for a service consumer. Both provider and consumer are roles played by software agents on behalf of "" "(1). Service-oriented service is a collection of services. Each service can communicate with each other (including simple data transfer and multiple services to participate in one activity), which provides some external interfaces for each system. Thereby the purpose of integrating various systems. The industry also has some corresponding architecture, such as DCOM.CORBA.J2EE. But you can't completely implement cross-system integration. Personally feel that the reasons are as follows:

1. Interface definition language cannot be received by different systems. Both DCOM.COBRA or J2EE have their own interface definition languages ​​(they are binary). They can't be accepted by other systems. Once the interface is set, it is difficult to change. And the user's needs are constantly changing. .

2. Used is a binary network protocol to perform data communication. It is difficult to cross the firewall, and the protocols of each used are not received, this is especially the use of the Internet

At this time, a new architecture appears, it is XML Web Services, Microsoft's definition is: "XML Web Services is a programmable entity that provides specific functional elements (such as application logic), any quantity, probable Full-different systems can access it with a common Internet standard such as XML and HTTP. Its core feature is highly abstracting between the implementation and use of the service. "Web Services is quickly accepted by each platform. Compared to other architectures, its advantages are:

1. Interface definition language. It uses WSDL as an interface definition language. This is a Document based on XML format, and the text can be known by various systems and platforms.

2. Use HTTP, SOAP, SMTP and other other widely accepted protocols to communicate. And HTTP is one of the foundation of the Internet.

How do you in-depth understanding of Web Services? Personally, you should start from the following aspects:

First, the purpose

It is a way to implement SOA, to connect different systems and computing devices. Implementation of system and data

It is easy to access data from different systems and computing devices. Don't care about how these data is stored in their respective systems and devices. It can also be said that it is not necessary to care about how to encapsulate (Similar to OO Box) II. Definition

XML Web Service As the nameship is to use XML to provide web services. In fact, it is strictly said that WEB can be, that is, XML Service, because not all Web Service requires WebServer. The service is to provide the function to the user, which is to provide an interface to the user, which is the web service. So Web Service is definitely not a new distributed object. And DCOM, CORBA, J2EE are inherently distributed objects.

Three.

1. Some components that can process XML.

First XML Web Service (or Web Service) is able to process XML, as for how to process XML components is designed. Different languages, platforms have different ways. It can be OO (object-oriented). It can also be other ways. NET is implemented by some classes provided by .NET Framework

2. XML documentation

As we say that one of the Web Service Advantages is based on XML-based documents (IDL), because Web Service is a SOA (service-oriented), the SOA's goal is to build a loosely between the system. Coupling, the service and consumer servers cannot use Object as a link or contract, which must use the XML document as a contract. That is to make the service provider and consumers understand Contract Incidence .Web Service uses WSDL to describe the XML document. That is to describe the external interface. Use XML Schema to describe the data in the document

3. Vectors of XML documents

With an XML document, you need a protocol that carries it. Web service uses SOAP as a load. SOAP: Simple object access protocol, strictly, this name is wrong, because it is not used to access objects. The definition of MS is "SOAP is an XML-based, simple lightweight protocol for exchange structured and type information on the web." It carries the XML document in a envelope. The envelope is divided into two parts: the HEAD and the envelope (Body). Heads are generally used to hold some auxiliary information, such as security (signature and encrypted data) and routing information, envelopes to save the interface description and specific data of the service.

4. The address of the service

Use to tell the service consumers where you can access the service, where is the service is located,

Microsoft provides UDDI (general description, discovery, and integration).

Net implementation of Web Service is through ASP.NET. It encapsulates a lot of details, making developers to develop WebService, but the result is that the understanding is difficult. (MS consistent style).

l Call the Web Service through the form of a web method.

The previous exhibition is actually an XML documentation between Web Service, considering a lot of programmers.

Not accustomed to direct operation of XML (like operational objects and methods thereof), will receive it in .NET

XML document converts the value of the parameter of the object or as a method, and the value or pair

Anti-sequencing into XML documents to send back to service consumers, service consumers can use traditional

Call the method of the object to send a request to the service provider to achieve the number of desired

according to. From consumers to apply for services to obtain the results of the corresponding results (2) -:

It can be seen from this flowchart (2). The client wants to call the Web Service first to send a message.

And the server knows that there is a consumer to call it. So in a sense .web

Service is a message-based architecture, but the message is based on XML-based documentation.

l Agent production

The role of the agency class is to facilitate communication with the web service. In .NET can be automated and hand

The way is generated, both are generated according to the service's WSDL file. As mentioned earlier

Programmer's habitual usage, .NET will define the XML document to be objects, and it is also the same in the proxy class. This will give us an illusion, it seems that the client regenerates the server object. For example: one

Web method TEST returns an Objecta to customers

Public Class Objecta

{

Public String Fielda

Public String Fieldb

}

Then generate an Objecta in the agent class. Its structure and server Objecta is one

Sample. But in fact, this is just .NET in order to make it easy for us to use Web Service (this is also

Many people think that WebService is one of the reasons for access to remote objects). WEB service customers

In terms of receiving only XML documents, the data in the document is described in XML Schema. As for

How to use it is the features of each web client, which will put some complex custom customizations for .NET.

The XML Schema type is converted into Object. Other clients will not be converted to Object .. for example

SOAP TOOKIT. It will be converted into an XML node (Node) object

Here is a practical project to illustrate how to implement Web Service.

I. Project Overview

A company has an existing product Producta. (PA), it needs to get some data to perform business processing. These data can vary by region and time, and data is determined by the corresponding government agencies, and the data of government agencies in different regions is different. Each change needs to notify the product user in the form of a letter, or by the company Organize and tell the user to update. This causes different versions of different versions, users to upgrade difficulties, and the data between government agencies is difficult to communicate and comparison.

Second. Solution

With the function of Web Service, all government agencies' data is disclosed (of course, J) of the authority must be permission. Product (PA) As the WebService client, you can access different data in real time, so that both the products and data, the data and data are seamless between users, and data.

III. The specific implementation of two participants with services: the consumer of the service providers and services for the product (PA) is a consumer of services. So it is just a Web Service Client. Can be any type of program. The existing PA is a VB version of the program that can access different services through proxy classes. For data (A.B.C ....). They are service providers to service consumers. Since the user needs to be able to directly query some data, we have a website for each data to make it easy for users to query (using ASP.NET), we said that the service is open to the interface It does not need to care about how to implement in their respective systems, so the functional and data itself can still use existing technology. Implementing function and data sections or three-layer architecture, using Web Service as a separate layer (FACADE layer). The frame diagram is as follows: .NET provides an ASMX file as a file as a specific implementation. There are several problems in the process of implementation:

l SOAP's format SOAP is a carrier of the service, which itself has a certain format. For envelopes in SOAP. There are two formats Document and RPC. There are two formats for the data in the SOAP request and response: Encoded and Literal. Document style refers to one or more consecutive message section (3) that format the body element into a body element (3). It is the RPC style using XSD Schema It means that the contents of the SOAP using SOAP according to the SOAP specification (which is also the sections 7 of the usual SOAP specification) (3). It is packaged in an XML element in an XML element, not You need to use the XSD Schema Literal style to reside in the body element and encode the xml document. Using the XSD Schema Encode style is set in formatting the coding rules in the SOAP specification. It doesn't need XSD schema in ASP.NET Document / Literal is the default setting. Literal can only be used under operation, while Encoded can be used under Document and RPC at the same time. We can customize the style of SOAP. .NET provides properties to accomplish this feature: SOAPDocumentMethod SOAPDocumentService SOAPRPCMETHOD SOAPRPCSERVICE Specific Use please refer to MSDN

转载请注明原文地址:https://www.9cbs.com/read-7055.html

New Post(0)