Cook Computing

Example of XmlRpcProxyGen

October 6, 2002 Written by Charles Cook

An example of how the new XmlRpcProxyGen class is used. First define an interface which represents the methods exposed by the XML-RPC server, marking the interface with the URL of the server if required. Each method is marked with the XmlRpcMethod attribute which allows the name of interface to be mapped onto the XML-RPC server method. For example:

interface IBetty
  string GetStateName(int stateNumber); 

  string GetStateNames(XmlRpcStruct request); 

Second, call the static Create method of XmlRpcProxyGen to create an instance of a dynamically generated class which implements the interface and derives from XmlRpcClientProtocol:

IBetty betty = (IBetty)XmlRpcProxyGen.Create(typeof(IBetty));

Finally call one or more of the interface methods:

string stateName = betty.GetStateName(3);

XmlRpcStruct stateNumbers = new XmlRpcStruct();
stateNumbers.Add("state1", 1);
stateNumbers.Add("state2", 2);
string stateNames = betty.GetStateNames(stateNumbers);

I'm hoping to issue a new release of XML-RPC.NET containing XmlRpcProxyGen sometime over the next day or two.