Constructing remote services using XML technology in PHP (UP) _php tutorial

Source: Internet
Author: User
Tags http post knowledge base
The future of the web will be a service-centric WEB,XML_RPC standard making it very easy to write and apply services. This article introduces the XML_RPC Standard and its PHP implementation, and demonstrates how to develop XML_RPC services and client programs in PHP with examples.

One, service-type web
From the simple approach adopted by the content provider to the future vision of UDDI (Universal description,discovery and integration), the industry already has a lot of notes and comments about the "serviced Web". For the start-up phase of the web, it is just a distribution center of documents, providing only a few browsable information. As the web develops, running services on the web is increasingly appealing. In the future, the web will become a carrier for customers and other enterprises to provide convenient services. Collaboration between business-to-business and business-to-business models can be seen as a service web.

A very important question is, what services are available on the Web? The web can provide a lot of services, some of which are now in use, and some services will appear in the near future. To illustrate the problem, a small subset of the services available through the Web are listed below:

A topic-oriented vertical search engine.
A knowledge base for users to find information.
Users can ask questions of the expert system.
Banking services.
News and information Publishing services.
Digital payment-related services.
Graphics processing services.
Health and health services.

So what's the right way for businesses and organizations to deliver services through the Web? This is a very important question. Today, some services provide HTML interfaces that provide services in the form of documents, but what is hidden behind the service interface? In the race to occupy the Web, Web browsers are not alone, and devices like mobile phones, handheld devices, and microwaves want to access the Web, query databases, transform data, extract information, and so on. To implement a truly serviced web, there should be another layer beneath the presentation layer (HTML).

Second, XML_RPC standard
XML is perhaps the most important standard in nearly 10 years, and the XML Glossary (vocabulary) provides the cornerstone for an enterprise to construct a service environment. Building a serviced web is necessary to learn the XML_RPC standard, not only because XML_RPC is useful for putting services on the web, but also because XML_RPC is a well-formed, easy-to-use standard. The standard of service delivery is extremely important for business-to-service services, and companies that work together to comply with standards can gain rapid growth with services from other companies. It cannot be imagined that a truly serviced web can be built on a variety of private service standards, and that services must have a standard to follow.

XML_RPC is a standard for distributed processing on the Internet. RPC is the abbreviation for remote Procedure call, a remote call mechanism that invokes procedures that may reside on other machines and may be written in other languages. Remote procedure calls are an important pillar of distributed computing. For example, in a distributed computing environment, where we can find and take advantage of the process of performing addition and subtraction operations on other machines, the process of performing the addition may be written in APL, run on the RS6000 machine, and the process of performing the subtraction operation may be written in C and run on UNIX. Other developers who want to use this distributed calculator can also use them, or he can choose a better calculator.

In RPC, the process (Procedure) is the most important component, and the server provides the process for the client to invoke. The procedure can receive parameters and return results. XML_RPC uses HTTP as the protocol carrier to implement RPC mechanisms by sending and receiving XML vocabularies for data. The XML_RPC server receives the XML_RPC request and returns a XML_RPC answer, XML_RPC the client sends a XML_RPC request and receives a XML_RPC response. Servers and customers must process responses and requests as required by the XML_RPC standard.

Iii. XML_RPC Agreement
The complete XML_RPC specification can be found in the Http://www.xmlrpc.com/spec. Here is a description of its essentials.

3.1 XML_RPC Request

The XML_RPC request should be an HTTP POST request whose body is in XML format. The XML part of the request is formatted as follows:

<?xml version= "1.0"?
<methodCall>
<methodName> Examples.getstatename </methodName>
<params>
<param>
<value> in </value>
</param>
</params>
</methodCall>


The URL where the specified data is sent is not specified here. If the server is dedicated to RPC processing, it may be "/". The payload in the XML document above is a "methodcall" structure. The methodcall must contain a "methodName" child element, and the "MethodName" child element contains a string that describes the method to be called. How to interpret the content of "MethodName" is entirely up to the server, for example, it can be the name of an executable file, a name that can be recorded in a database, or anything else. If the procedure receives a parameter, "Methodcall" can contain a "params" element and several "param" child elements. Each "param" element contains a value with a type descriptor, and the type descriptor is shown in the following table:


Tag description
Or <int> four-byte signed integer, such as 12
<boolean> 0 (false), or 1 (true)
A <string> string, such as "Hello World"
<double> double-precision signed floating-point numbers, such as-12.214
<dateTime.iso8601> Date/time, such as 19980717t14:08:55
<base64> base64 encoded binary data, such as Ew91igbid0ihjlqgdghpcye


3.1.1 Structure

The value can be a structure with The element description. Each Contains multiple Each Contains a and a 。 The following is a structure consisting of two elements:

<struct>
<member>
<name> name </name>
<value> <string> member1 </string> </value>
</member>
<member>
<name> Member2 </name>
<value> </value>
</member>
</struct>


can be nested, any Can contain or any other type, including.

3.1.2 Array

Values can be array types, and arrays are described by elements. Each element contains a ElementsElement can contain any number of Elements. Here is an example of an array element:

<array>
<data>
<value> <boolean> 0 </boolean> </value>
<value> 9 </value>
<value> <string> Hello </string> </value>
</data>
</array>


element has no name. As shown in the preceding example, the value of an element can be of various types. Elements can be nested, any Can contain or other types, as described above 。

3.2 XML_RPC Response

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

<?xml version= "1.0"?
<methodResponse>
<params>
<param>
<value> <string> ABCDEFG </string> </value>
</param>
</params>
</methodResponse>


May contain a Structure, or may contain a The structure, depending on whether the procedure call was successful. The structure is the same as in an XML request, and the syntax for the element is as follows:





faultcode
4


faultst Ring
error!



/ fault>

http://www.bkjia.com/phpjc/313938.html www.bkjia.com True http://www.bkjia.com/phpjc/313938.html techarticle The future web will be a service-centric web, The XML_RPC standard makes it very easy to write and apply services. This article introduces the XML_RPC Standard and its implementation of PHP, and demonstrates through examples how to ...

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