Using XML technology to construct remote services in PHP (I)

Source: Internet
Author: User
In the future, the Web will be service-centered. XML_RPC makes writing and application services very simple. This article introduces the XML_RPC standard and its PHP implementation, and demonstrates how to develop the XML_RPC service and customer program in PHP through examples. I. service-oriented Web services from the simple method adopted by content providers to the UDDI (UniversalDescription, DiscoveryandI future Web services will be service-centric Web, XML_RPC standard makes writing and application services very simple. This article introduces the XML_RPC standard and its PHP implementation, and demonstrates how to develop the XML_RPC service and customer program in PHP through examples.

I. service Web
From the simple method adopted by content providers to the future ideas of UDDI (Universal Description, Discovery and Integration), there have been a lot of comments on "service Web" in the industry. In the early stage of Web development, it is just a distribution center for documents, providing only some information that can be browsed. With the development of Web, running services on the Web is becoming more and more attractive. In the future, Web will become a carrier for enterprises to provide convenient services for customers and other enterprises. The collaboration between B2B and B2C models can be seen as a Service Web.

A very important question is what services can be provided on the Web? Web provides many services, some of which are currently in use, and some will appear in the near future. To illustrate the problem, a small part of the services that can be provided through the Web are listed below:

A topic-oriented vertical search engine.
The knowledge base for users to find information.
You can consult an expert system.
Banking services.
News and information publishing services.
Digital payment-related services.
Graph processing service.
Health and Health Services.

So what is the correct way for enterprises and organizations to provide services through the Web? This is a very important issue. Today, some services provide HTML interfaces. they provide services in the form of documents, but what is hidden behind the service interface? In the competition to occupy the Web, Web browsers are not alone. mobile phones, handheld devices, and microwave devices all want to access the Web, query databases, convert data, and extract information. To implement a truly service-oriented Web, there should be another layer under the presentation layer (HTML.

II. XML_RPC standard
XML is perhaps the most important criterion in the past 10 years. The XML Vocabulary (Vocabulary) provides a cornerstone for enterprises to construct a service environment. To build a service Web, it is necessary to learn the XML_RPC standard. this is not only because XML_RPC is useful for putting services on the Web, but also because XML_RPC is a standard that has been formed and is easy to use. For B2B services, the standards for providing services are extremely important. companies that comply with the standards can use the services provided by other companies to achieve rapid growth. It cannot be imagined that a real service Web can be established based on various private service standards, and services must have a standard that can be followed.

XML_RPC is a standard for Internet distributed processing. RPC is short for Remote Procedure Call. it is a Remote Call mechanism used to Call processes that may reside on other machines and may be written in other languages. Remote process calling is an important pillar of distributed computing. For example, in a distributed computing environment, we can find and use the process of performing addition and subtraction operations on other machines, the process of performing addition operations may be written in APL and run on RS6000 machines. the process of performing subtraction operations may be written in C and run on Unix. Other developers who want to use this distributed calculator can also use them, or they can use another better calculator.

In RPC, the process (Procedure) is the most important component, and the server provides the process for the client to call. The process can receive parameters and return results. XML_RPC uses HTTP as the protocol carrier and implements the RPC mechanism through the XML vocabulary for sending and receiving data. The XML_RPC server receives the XML_RPC request and returns the XML_RPC response. the XML_RPC client program sends the XML_RPC request and receives the XML_RPC response. Servers and customers must handle responses and requests as required by the XML_RPC standard.

III. XML_RPC protocol
The complete XML_RPC specification can be found at The following describes the key points.

3.1 XML_RPC request

The XML_RPC request should be an http post request whose body is in XML format. The XML format of the request is as follows:

<? Xml version = "1.0"?>
<MethodName> examples. getStateName </methodName>
<Value> <i4> 41 </i4> </value>

The URL where the data is sent is not specified here. If the server is dedicated for RPC processing, it may be "/". The payload in the preceding XML document is a "methodCall" structure. MethodCall must contain a "methodName" sub-element. The "methodName" sub-element contains a string describing the method to be called. The explanation of "methodName" is entirely determined by the server. for example, it can be the name of an execution file, the name recorded in the database, or anything else. If the process receives parameters, "methodCall" can contain one "params" element and several "param" sub-elements. Each "param" element contains a value with a type descriptor, as shown in the following table:

Tag description
<I4> or <int> four-byte signed integer, such as 12
<Boolean> 0 (false), or 1 (true)
<String> string, such as "Hello World"
<Double> double-precision signed floating point number, such as-12.214
<DateTime. iso8601> date/time, for example, 19980717T14: 08: 55
<Base64> base64 encoded binary data, such as eW91IGbid0IHJlQgdGhpcyE

3.1.1 structure

The value can be a structure. Element description. Each Contains multiple , Each Contains And one . The following is a structure composed of two elements:

<Name> name </name>
<Value> <string> member1 </string> </value>
<Name> member2 </name>
<Value> <i4> 19 </i4> </value>

Can be nested, any Can contain Or any other type, including.

3.1.2 array

The value can be an array type, and the array is described as an element. Each element contains Element,The element can contain any number Element. The following is an example of an array element:

<Value> <boolean> 0 </boolean> </value>
<Value> <i4> 9 </i4> </value>
<Value> <string> Hello </string> </value>

The element has no name. As shown in values, the element values can be of various types. Element can be nested, any Can contain or other types, as described above .

3.2 XML_RPC response

The XML_RPC response is an HTTP response. the content type is text/xml. The format of the response body is as follows:

<? Xml version = "1.0"?>
<Value> <string> ABCDEFG </string> </value>

May contain Structure, or may contain Structure, which is determined by whether the process call is successful. The structure is the same as that in XML requests, The element syntax is as follows:

<Name> faultCode </name>
<Value> <int> 4 </int> </value>
<Name> faultString </name>
<Value> <string> Error! </String> </value>

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: 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.