|
The emergence of the Internet has made more applications network-aware and has thrown them all into the same domain. The mish mash of different protocols that are used by the ever-growing number of applications has made the task of creating new applications daunting for developers. The developers now have to familiarize themselves with several different protocols. RPCs address this problem by exposing a standard, generalized interface by which a method residing at a remote endpoint can be invoked, and its return value received like any other native procedure from within the program code. The developer need not worry about how and in what format the data is sent between the two endpoints. In some cases they may be unaware that they are even using an RPC!
<?xml version="1.0"
encoding="UTF-8" ?>
<methodCall>
<methodName>emailValidator.verify</methodName>
<params>
<param><value><int>54</int></param>
<param><value><string>RG5H4</string></param>
</params>
</methodCall><?xml version="1.0"
encoding="UTF-8" ?>
<methodResponse>
<params>
<param><value><boolean>1</boolean></param>
</params>
</methodResponse><?xml version="1.0"
encoding="UTF-8" ?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>1</int></value>
</member>
<member>
<name>faultString</name>
<value>Not enough parameters.</value>
</member>
</struct>
</vlaue>
</param>
</params>
</methodResponse>- Both endpoints must respect the visibility of the object's members (e.g: public, private, protected).
- After each operation the data will need to be revalidated to ensure that it respects any constraints.
- Serializing and unserializing an object is a resource intensive task
- As a single operation typically affects only a single object property, much of the serialized data is redundant and gets passed back and forth unnecessarily.

RPC Methods mapped to customer object:
Customer.getAddress(id)
Customer.getName(id)
Customer.setName(id, newName)
Customer.find(pattern)
The RPC client only needs to work with one piece of data: the customer ID. This is passed along with each RPC call and serves to uniquely identify the object instance. Although the data still needs to be serialized, this is now only the servers job and it retains complete control over all the data that is connected with the customer.
Another solution is to use SOAP (Simple Object Access Protocol), an application of RPC and WSDL (Web Services Description Language). It provides a robust way to work with remote object instances. This will be explored in more detail in the next article in this series.
More and more websites are making their services available via RPC. This promotes the sharing of information and the re-usability of existing services to enrich the content that web developers can provide. For example, a typical web application may call on news services, search engines and online payment services to provide the functionality that would otherwise require code written by in-house developers.
In the following example I will demonstrate how to use the PEAR RPC client in PHP to call several APIs provided by the online photo sharing service Flickr. The example will display the four most recent public pictures added to a specified users Flickr account.
Flickr is a new online photo-based service which allows its users to upload, share, tag and add comments to their pictures as well as order physical reprints. It also provides a web service API, which is made accessible via RPC. The API allows the developer to do anything a normal user can do but via the API. If you wish to access the API, you first need to sign up for an account and obtain an API Key, this needs to be passed as an argument to each RPC called on Flickr.
The API's provided by Flickr typically expose multiple optional arguments. For this reason each RPC accepts a single parameter containing a structure, each member of which is an argument that is to be passed to the RPC. This enables the developer to send only the parameters which are needed in any order:
<struct>
<member>
<name>apiKey</name>
<value><string>123456</string></value>
</member>
<member>
<name>userName</name>
<value><string>visualAd</string></value>
</member>
</struct>
require_once 'XML/RPC.php';- XML_RPC_Client - provides the transport by which RPC calls are sent and RPC responses received.
- XML_RPC_Message – used to store a RPC call and its parameters
- XML_RPC_Value – Represents an XML-RPC value and its data type.
- XML_RPC_Response
– Holds an XML-RPC response.
[ Next Page ]
| Comments: | ||
No Messages FoundYou can post questions/corrections/feedback here
| ||
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


