Setting up the python server
import calendar, SimpleXMLRPCServer
#The server object
class Calendar:
def getMonth(self, year, month):
return calendar.month(year, month)
def getYear(self, year):
return calendar.calendar(year)
calendar_object = Calendar()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
server.register_instance(calendar_object)
#Go into the main listener loop
print "Listening on port 8888"
server.serve_forever()
Setting up the C# client
1. Download the helping DLL's from http://xml-rpc.net/
2. Create a proxy interface:
using System;
using CookComputing.XmlRpc;
namespace XMLRPCclient
{
[XmlRpcUrl("http://127.0.0.1:8888/")]
public interface IClientCalendarProxy : IXmlRpcProxy
{
[XmlRpcMethod("getMonth")]
string getMonth(int p1, int p2);
}
}
3. Init & run your client using the upper defined proxy interface (make sure the URL points to the port of the web service)
using System;
using CookComputing.XmlRpc;
namespace XMLRPCclient
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
IClientCalendarProxy proxy = XmlRpcProxyGen.Create<IClientCalendarProxy>();
string ret = proxy.getMonth(2002,8);
Console.WriteLine(ret);
}
}
}
Useful links:
import calendar, SimpleXMLRPCServer
#The server object
class Calendar:
def getMonth(self, year, month):
return calendar.month(year, month)
def getYear(self, year):
return calendar.calendar(year)
calendar_object = Calendar()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
server.register_instance(calendar_object)
#Go into the main listener loop
print "Listening on port 8888"
server.serve_forever()
Setting up the C# client
1. Download the helping DLL's from http://xml-rpc.net/
2. Create a proxy interface:
using System;
using CookComputing.XmlRpc;
namespace XMLRPCclient
{
[XmlRpcUrl("http://127.0.0.1:8888/")]
public interface IClientCalendarProxy : IXmlRpcProxy
{
[XmlRpcMethod("getMonth")]
string getMonth(int p1, int p2);
}
}
3. Init & run your client using the upper defined proxy interface (make sure the URL points to the port of the web service)
using System;
using CookComputing.XmlRpc;
namespace XMLRPCclient
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
IClientCalendarProxy proxy = XmlRpcProxyGen.Create<IClientCalendarProxy>();
string ret = proxy.getMonth(2002,8);
Console.WriteLine(ret);
}
}
}
Useful links:
- Start your exploration of XML-RPC on the official home page. The specification is also a very easy read.
- For reference, use the official Python docs for the XML-RPC client and server modules.
- Browse Useful Information Company's XML-RPC page for more sample XML-RPC services.
- If you plan to do significant work using the protocol, do read and bookmark Eric Kidd's XML-RPC HOWTO.
- Read Using XML-RPC for Web services: Getting started with XML-RPC in Perl, by Joe Johnston for an introduction to XML-RPC, and the follow-up XML-RPC Middleware.
1 comment:
Post a Comment