Web Services

SOAP IN Web services

SOAP Tutorial

adplus-dvertising
XML-RPC
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.
Introduction to XML-RPC

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

XML-RPC Request Format
  • 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>
XML-RPC Response Format
XML-RPC responses nearly as like request. The procedure was executed correctly and returned appropriate results are totally based on responces. If response returned a value then application may be error free. XML-RPC responses contain following information
  • 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>

XML-RPC Fault Format
XML-RPC Fault is a type of responses, they contained:
  • 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 Examples (in .net)

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); 
}
The proxy instance is generated using static method Create of the XmlRpcProxyGen class.
ICityName proxycity = XmlRpcProxyGen.Create<ICityName>();
The method on the proxy can then be called to make the XML-RPC request to the serve.
string cityName = proxycity.GetCityName(45);
XML-RPC Services

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";
  }
}
As well as specifying an XML-RPC method the XmlRpcMethod attribute is here used to specify that the method is to be called using the XML-RPC protocol as examples.getCityName, not the name of the method used in the Service class. Alternatively the service class may also derive from an interface which defines the XML-RPC methods. The interface can then be also used to generate a proxy class as described above.

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";
  }
}
  1. A class may implemented many XML-RPC methods not like a single as shown in above example.
  2. The resulting assembly DLL placed in the bin directory of an IIS file directory
  3. To dispatch HTTP requests to the custom handler implemented by class XmlRpcService.
  4. 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