3. Servers 3.1 What are the different ways in which an XML-RPC server can be implemented? There are three ways of implementing an XML-RPC server using XML-RPC.NET: - In IIS using a class derived from XmlRpcService.
- Using an XML-RPC formatter with .NET Remoting.
- In IIS using an XML-RPC formatter with .NET Remoting.
3.2 How do I implement an XML-RPC server in IIS? Class XmlRpcService implements an HTTP Handler which exposes the IHttpHandler and IRequiresSessionState interfaces. When a class derived from XmlRpcService is configured via a web.config file, incoming XML-RPC requests will be directed to the handler by the ASP.NET runtime. Implementing the Service XmlRpcService is derived from, adding the custom application function of the Service. The derived class contains one or more public methods which represent the required XML-RPC methods. For example, the SumAndDifference example would be implemented like this: public class MetablogAPI : XmlRpcService, IMetaWeblog { #region IMetaWeblog Members public object editPost(string postid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish) { cmsgames3.Blog_Post blog_Post = db.Blog_Posts.Single(p => p.postid == int.Parse(postid)); Post2Blog_Post(username, password, ref blog_Post, post, publish); db.SubmitChanges(); return true; } }
If this code is saved to a file called MetablogAPI.cs the Service can be built using the following command line: csc /r:system.web.dll /r:CookComputing.XmlRpcV2.dll /target:library MetablogAPI .cs
This will build a dll assembly called cmsgames3.dll.
Configuring the Service
The Service has to be placed in a virtual directory, say xmlrpc in this case, which has a sub-directory called bin. A configuraton file called web.config is created in the virtual root directory containing the following information to specify that the Service should be invoked when a HTTP request arrives for this URL: <configuration>
<system.web>
<httpHandlers>
<add verb="*" path="MetablogAPI.aspx" type="cmsgames3.MetablogAPI,cmsgames3"/> </httpHandlers>
</system.web>
</configuration>
The config file specifies that if the final segment of the URL is SumAndDiff.rem the handler in the class SumAndDifference will be invoked. Note that the assembly qualified name of the class is used so that ASP.NET knows which assembly to load the class from.
The HTTP verb is specified by a wildcard. The implementation in XmlRpcService handles both POST for XML-RPC method calls and GET to return an automatically generated documentation on the Service. XmlRpcService will reject any other requests with the appropriate HTTP response code.
The extension used for the URL is �.rem�. This is for convenience because ASP.NET is configured by default to handle a number of extensions including .rem, .aspx, and .asmx. Other extensions could be used, for example .xmlrpc would be an obvious choice, but this involves changing the configuration of the virtual directory via the IIS management snap-in.
Once the service is configured a quick check can be made by pointing your browser at the URL and verifying that the automatically generated help page is displayed. |