Mar
9
Writing an XML-RPC server or client in ASP.Net: Part 2


Posted: 9th March 2007
Tags: ,
Posted in Misc..
Comments: 4 Comments »

In my previous article I covered how to setup an XML-RPC server in .Net, in particular looking at how to service XML-RPC MetaWebLog API requests. In this second part I am looking at how we can easily construct an XML-RPC client to ping blog directory or search services such as Technorati, Google BlogSearch, blo.gs etc.

If you have not read part one, I recommend you take a look at this article first as it covers the set-up and configuration of CooksComputing XML-RPC provider, which is required for this tutorial.

Creating an XML-RPC client proxy class

Before we can make and XML-RPC client request, we need to create a proxy/wrapper class to handle our client requests for us. In this example I am going to create a client that pings blogflux.com . To use their XML-RPC service you need to sign-up for a free account.

To ping blogflux.com we need to send an XML-RPC call to http://pinger.blogflux.com/rpc/

Which is configured to accept pings that follow the WebLog ping format.

Firstly, we will create our proxy class in our App_Code directory as follows:

using System.Reflection;
using CookComputing.XmlRpc;
 
[XmlRpcUrl("http://pinger.blogflux.com/rpc/")]
class BlogFlux : XmlRpcClientProtocol{
 
     [XmlRpcMethod("weblogUpdates.ping")]
     public XmlRpcStruct ping(string weblogname, string weblogurl)
     {
          return (XmlRpcStruct)Invoke(MethodBase.GetCurrentMethod(), new object[] { weblogname, weblogurl });
     }
 
}

Here we need to insert a compiler directive before the class definition which indicates the URL we want this proxy to communicate with, in this case: pinger.blogflux.com/rpc/. We then need to insure that our class inherits from XmlRpcClientProtocol. Once we have done this we can define the methods that we want to call on the remote RPC-XML server. the WebLog ping protocol supports two method calls, weblogUpdates.ping and weblogUpdates.extendedPing. The most widely implemented in the weblogUpdates.ping method, which takes two parameters, the first being a string containing the name of your blog, the second (again a string) the URL of your blog. webblogUpdates.ping returns a XML-RPC struct indicating whether the ping succeeded or not, so our method returns and XmlRpcStruct and to initiate the call we use the following code:

Invoke(MethodBase.GetCurrentMethod(), new object[] { weblogname, weblogurl});

As you can see we pass the parameters onto the XML-RPC client call within the second parameter of the Invoke method call and all XML-RPC methods are stored in an array of type object.

Once we have our client proxy defined, we can easily create and invoke a remote XML-RPC call as follows:

BlogFlux bf = new BlogFlux();
bf.ping("Jon Milet Baker’s Blog", http://www.miletbaker.com/blog/);

And if we want to check the results of our client XML-RPC call we can do the following.

XmlRpcStruct struct = bf.ping("Jon Milet Baker’s Blog", http://www.miletbaker.com/blog/);
label1.text = struct["errMsg"];

The XML-RPC protocol is widely adopted especially by blog platforms. This tutorial covers the basics of XML-RPC and I recommend reading Charles Cooks FAQ for more information, but as you can see this code could easily be adapted for any Remote Procedure Call requirement and provides an alternative to SOAP based Web Services.

Comments below..

Advertisement

 




Comments

Note: You can leave a response, or trackback from your own site.

 
 


Fulin Xiang
12/08/2008
6:23 am

Comment:

Hi,

Do you know how to use XML-RPC.NET to create a client that can connect to a non-html endpoint (where there is no http server, just IP address and port number)?

Thank you!

 
 
Comment:

Hai,

Can you please send me a link for a video tutorial to understand clearly about xml rpc.

 
 
Comment:

Hi

unfortunately I do not know the answer to either of these. XML-RPC is quite an enigmatic protocol I have not seen any videos. As for using XML-RPC over sockets directly. This should be possible I have not done any .Net for a very long time but I think you can transmit strings rather than have to byte encode. Just transafer your XML-RPC as a string between a client socket and server socket (I may be confusing with Java here sorry) and then constuct an XMLRPCStruct. In fact you can possibly serialize the XMLRPCStruct over the wire. Maybe someone with more recent .Net experience can help you.

Regards,

Jon

 
Add a comment:

 



    My Web Apps..

    Stubmatic.com
    Stubmatic is an online box office service for venues, promoters, bands, theatres and anyone with tickets to sell. Our members sell tickets online without incurring any booking fees and we provide all the tools to promote, sell and track sales.

    View Jon Baker's profile on LinkedIn


    View blog authority