| Previous | Home | Next |
RPC
RPC is a older technology stands for Remote Procedure Call. RPC is a mechanism to call function or procedure that are available on a remote computer. RPC provides a mechanism to the developer and define interfaces which must be called over a network. These interfaces can be as simple as a single function call.- XML-RPC provide facility to computer to call procedure from other remote computer and make function across network.
- XML-RPC uses the HTTP protocol to transfer information between a client computer and a server computer. It uses XML vocabulary to describe nature of request and response.
- XML-RPC client specified only a procedure name and parameters and the server returns fault or response to the client but both are in XML format.
- With XML-RPC and web services, however, the Web becomes a collection of procedural connections where computers exchange information along tightly bound paths.

Why XML-RPC ?
If you want to establish communication easily between client and server, XML-RPC be the better way. It integrate multiple or more computing environment easily without sharing complex data structure. XML-RPC make easy to share information or program in a single computing environment. XML-RPC uses standers XML vocabulary to response and request.XML-RPC Data Model
XML-RPC simple types mapped onto .NET data types.
XML-RPC simple types are mapped to and from the following .NET types:
| double | System .Double | 64-bit floating-point numbers |
| base64 | System .Byte[] | |
| boolean | System .Boolean | true (1) or false (0) |
| string | System .String | XML-RPC.NET always outputs the string element instead of just a value element with text content |
| i4 int | System .Int32 | XML-RPC.NET by default outputs i4 |
| dateTime iso8601 | System .DateTime | Dates in ISO8601 format: CCYYMMDDTHH:MM:SS |
| i81 | System .Int64 | Extension to XML-RPC. |
The given basics types are always enclosed in a value elements.
- Strings may be enclosed in a value element but omit the string element.
- These basic types may be combined into two more complex types, arrays and structs. Arrays represent sequential information, while structs represent name-value pairs, much like hashtables, associative arrays, or properties.
<value><array><data>
<value><string>Hello </string></value>
<value><string>Good </string></value>
</data></array></value>
.......................................................
<value><array><data>
<value><int>7</int></value>
<value><int>124</int></value>
</data></array>
.......................................................
<value><array>
<data>
<value><boolean>1</boolean></value>
<value><double>42.14159265</double></value>
</data></array></value>
-
It is a combination of HTTP headers and XML contents
- XML content used the data type structure which help to passed parameter according when you call procedure and it also contains additional information about calling procedur.
- The HTTP headers provide a wrapper for request to passing over the Web. Request contained at least single XML document, whose root element is a methodCall element.
- Each methodCallelement contains two element first one is the methodName and second element is a params element.
- The methodNameelement identifies the name of the procedure to be called.
- The params element contains a list of parameters and their values.
<?xml version="1.0"?>
<methodCall>
<methodName>AreaSquare</methodName>
<params><param>
<value><double>2</double></value>
</param></params>
</methodCall>
- An XML-RPC response contain only one parameter.
- That parameter may be any type. It may be array type, struct type etc. Therefore it returns multiple values
- It also return boolean values.
<?xml version="1.0"?>
<methodResponse>
<params><param>
<value><double>4</double></value>
</param></params>
</methodResponse>
- A fault will also have an error code which make easy to understand that what type error
- If any problem to processing requests then methodResponse element contain fault element instead of a params element
- Fault element contain a single value like a params element that indicates that something wrong
<?xml version="1.0"?>
<methodResponse>
<fault>
<value><string>No Method</string></value>
</fault>
</methodResponse>
.........................................................
<?xml version="1.0"?>
<methodResponse>
<fault><value><struct>
<member>
<name>name</name>
<value><int>26</int></value></member>
<member>
<name>message</name>
<value><string>No Method</string></value>
</member></struct></value></fault>
</methodResponse>
XML-RPC Client
First create client code for calling XML-RPC servers. Interface representing the XML-RPC end-point and then use the XmlRpcProxyGen class to automatically generate the code for the proxy.
[XmlRpcUrl("http://...")]
public interface IcityName : IXmlRpcProxy
{
[XmlRpcMethod("examples.cityName")]
string GetCityName(int cityNumber);
}
ICityName proxycity = XmlRpcProxyGen.Create<ICityName>();
string cityName = proxycity.GetCityName(45);
The model for XML-RPC Services are SOAP-based Web Services implemented as part of ASP. Net and they running in Microsoft IIS web server environment . An XML-RPC Service is implemented in any language that compiled under CLR (Common Language Runtime). It is create by creating a class which derives from the XmlRpcService base class. Decorating the methods to be exposed via XML-RPC with the XmlRpcMethod attribute.
For example:
public class CityNameService : XmlRpcService
{
[XmlRpcMethod("examples.getCityName",
Description="Return name of city given its number")]
public string getCityName(int cityNum)
{
if (cityNum == 45)
return "Delhi";
else
return "Unknown";
}
}
For example:
public interface ICityName
{
[XmlRpcMethod("examples.getCityName")]
string GetCityName(int cityNumber);
}
public interface ICityNameProxy : ICityName, IXmlRpcProxy
{
}
public class CityNameService : XmlRpcService, ICityName
{
public string getCityName(int cityNum)
{
if (cityNum == 45)
return "Delhi";
else
return "Unknown";
}
}
- A class may implemented many XML-RPC methods not like a single as shown in above example.
- The resulting assembly DLL placed in the bin directory of an IIS file directory
- To dispatch HTTP requests to the custom handler implemented by class XmlRpcService.
- A web.config file is used.
For example
if r4r.com has a file directory called xmlrpc and the following config file is placed in the root directory of xmlrpc:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="cityname.rem"
type="r4r.CityNameService, CityNameService" />
</httpHandlers>
</system.web>
</configuration>
The Service can be invoked via the XML-RPC protocol at this URL:
http://localhost/xmlrpc/cityname.rem
| Previous | Home | Next |