Web Service Common Sense

Source: Internet
Author: User

1 The problem leads

A program on a server needs to display a list of orders on a Web page that accesses a program on a business Object server, reads the list of orders through it, and accesses the database server with the business Object Server. When a program on one computer calls a program on another computer, it is called a remote Procedure call (Procedure) RPC.

Different organizations define different RPC protocols:

(1) DCOM

COM objects are language-independent, and you can use any language to design COM objects that are designed to be called by other programs, but the COM object must be on the same computer as the calling program. To this end, Microsoft extended the COM model to address this problem. But one of the most serious drawbacks is the common problem with all Microsoft products: not across platforms.

(2) IIOP

The same functionality as DCOM, language-independent, and cross-platform support (COM's underlying functionality is provided by the operating system, so it is not cross-platform, and IIOP is provided by the object request Proxy orb).

But DCOM and IIOP technology are too complex, which greatly affected their promotion.

(3) Java RMI

Java promises "compile once, run everywhere" at birth, and Java provides remote method calls or RMI systems for remote computing. It's easier than any other language, and Java RMI has a unique feature: each time you call, you can transfer code, that is, if the remote computer you are going to call does not have the code you need, you can send your code to the remote computer to execute your code. The downside is that programmers can only use the Java language.

So is there a new RPC that inherits them a bit, but overcomes their shortcomings?

That's the Web Service.

2 Web Service2.1 Web service definition

A Web service means accepting a request, returning data, or performing a processing activity.

Broadly speaking, Web service is not the same as an XML Web service. The main discussion here is XML Web Service.

Design method of 2.2 XML Web service

Depending on how you send the request, you can divide it into two types:

XML-RPC: Encapsulates the method name and parameters in an XML format;

Network transport: This method only shows that the Web service takes an XML document as its input parameter, the format of the XML document is pre-defined, usually the XML schema pattern is used, and the service processes the document and executes the requested task.

2.2.1 Xml-rpc

The client sends a command encoded in XML to the server, which executes a remote procedure call and returns a response encoded in XML format.

For example we need to invoke the following API interface program:

struct Topicexchange.getchannels ()

Returns a list of channels that do not require parameters.

struct topicexchange.ping (string topicname,struct details)

Add the new record to the Topicname theme.

struct Topicexchange.getchannelinfo (string topicname)

Returns the contents of the Tiopcname channel.

Here we use the Xml-rpc method to request a call:

For Topicexchange.getchannels

1 < Methodcall > 2     < MethodName >topicexchange.getchannels</methodName>3</  methodcall>
View Code

This is one of the simplest requests.

For topicexchange.ping, we need to pass the arguments passed, which requires a string parameter and a struct parameter:

We notice that the value of the parameter is to indicate its type when it is passed, and XML-RPC defines 7 types of headings:

<int> (or <i4>, representing 4-byte signed integers), <boolean> (0 for false, 1 for true), <string>, <double>, < Datetime.iso8601> (Date/time value) and <base64> (binary number with Base64 encoding)

Next look at a function return value:

1 <Methodresponse>2     <params>3         <param>4             <value>5                 <struct>6                     <member>7                         <name>Books</name>8                         <value>9                             <struct>Ten                                 <member> One                                     <name>Url</name> A                                     <value><string>Http://www.baidu.com</string></value> -                                 </member> -                             </struct>                                the                         </value> -                     </member> -                     <member> -                         <!-- More - +                     </member> -                 </struct> +             </value> A         </param> at     </params> - </Methodresponse>
View Code

This shows that structs can also be nested.

2.2.2 Network Transmission

Web services allow us to send and receive messages using network transmissions. The most commonly used send protocol is HTTP.

HTTP contains two parts: the message header and the body of the message. There is a blank line between them.

The introduction to the HTTP protocol is very detailed in the following two articles, and we would like to express our gratitude here:

HTTP protocol explanation (really classic)

HTTP protocol Detailed

This allows us to use HTTP in the XML-RPC. For this we only need to do two things on the client:

For the HTTP method, the post mode is used;

For the message body, insert an XML document consisting of the XML-RPC request. Such as:

The message header defines the content of the request, which consists of the XML-RPC request. The server knows how to read and process the body of the message.

Web Service Common Sense

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.