Writing an XML-RPC server or client in ASP.Net: Part 2
2010-04-25 21:04
676 查看
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:
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:
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:
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/);[/code]
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.
相关文章推荐
- Writing an XML-RPC server or client in ASP.Net: Part 1
- Embed client-side JavaScript in an ASP.NET 1.1 web page from server side code
- A frame in a frameset may become blank on an ASP page or in an ASP.NET application(frameset 可能变成空白)
- Part 85 - Enable client side validation in asp.net mvc
- Implementing an XML-RPC Service with ASP.NET MVC
- using sql server or sql azure for session state store in asp.net
- Login control in an ASP.NET AJAX toolkit PopupControlExtender with a close button--write by Laurent Kempé
- Web Server and ASP.NET Application life Cycle in Depth [转]
- 4 ways to send a PDF file to the IE Client in ASP.NET 2.0
- Part 2 - View engines in asp.net mvc
- 设置页面的默认焦点控件和默认接受事件控件How Do I Set the DefaultFocus or DefaultButton in a Page Based on a Master Page in ASP.NET 2.0
- DropDownList Controls In an ASP.Net DataGrid
- Resolving Http 500 Server Errors in ASP.Net and IIS 5.1(转载)
- Server in ASP.NET-Core
- using Silverlight 4 in an ASP.NET MVC 3 application and accessing data with JSON
- Using the Index Server to create Query Page in asp.net
- ASP.NET利用CustomValidator的ClientValidationFunction与OnServerValidate来double check资料输入的正确性
- File Upload using jQuery AJAX in ASP.NET Web API or Http handler (AJAX上传文件通过Web API或 http handler)
- Run Tasks in an ASP.NET Application Domain