Clone wiki

LiteRpc.Client / Home

What is in the package?

The primary goal of this project was to facilitate using any json-rpc service from within any .NET project. You now nowadays, many softwares out there has the feature: the most familiar one may be Trac, a good extensible powerful issue tracker. You can also use this project alongside with LiteRpc.Server to make a client/server, very light-weight RPC system.

Geting Started

Using the library is very easy. You just have to add an interface for each json-rpc domain, containing the required methd signatures. Suppose you want to use Trac's json-rpc for deleting a ticket. The signature is documented as the following:

int ticket.delete(int id)

The corresponding C# interface would be:

interface ITicket
    int delete(int id);

What about the name of the domain? You now must decorate the interface with the required information, including the domain name and uri of the json-rpc service. Since most of developers prefer to save the uri in the configuration file (AKA app/web.config), we convinced the name of the appsettings key instead of the uri string.

[Rpc(UriSettingsKey = "TracRpcUri", DomainName = "ticket")]
interface ITicket
    int delete(int id);

Recall that you must add the following configuration to the web.config or app.config file:

     <add key="TracRpcUri" value="" />

That's it. Now you can easily call the method. For instantiating the interface, you can use the Setup class:

var ticket = Setup.CreateProxy<ITicket>();

Or, if you want to use Basic Credentials, use this form:

var ticket = Setup.CreateProxy<ITicket>(new NetworkCredential(username, password));

Then, to call the rpc method:

int result = ticket.delete(45);

This is the simplest case. The most complicated case is to get a result of complex type, not as simple as integer. For this to take place, the best solution is to create a class with the compatible signature. For example, if you want to call such a method in Trac:

struct ticket.status.get(string name)

The 'struct' keyword here means there is a class-like output containing several properties. Suppose we are interested in id and title properties. The best way is to define a class like this:

class Status
   public int id {get;set;}
   public string title {get;set;}

[Rpc(UriSettingsKey = "TracRpcUri", DomainName = "ticket.status")]
interface ITicketStatuc
    Status get(string name);

And in the case of 'array' you can freely use Status[], IList<Status> or even IEnumerable<Status> instead.

Update: You can now use unknown type, in which condition the library creates an anonymous type on-the-fly for returning the object. But note that, although the type can be nested by any depth, the nesting properties must not be arrays, nor the arrays must contain unknown objects. Anyway, currently the following syntax is valid and returns a valid C# object.

object get(string name);

Now, you can use it like this:

dynamic result = status.get("fixed");
string name =;

Update: You can now use Setup.CreateProxyFor method for initializing uri and domain name instead of RPC attribute.Infact, using Rpc attribute is optional!

var resolution = Setup.CreateProxyFor<IResolution>(new Uri(""), "ticket.resolution", new NetworkCredential("Username", "Secret"));

Aother feature, is that you can override Domain name and/or Method names using RpcMethod attribute:

[Rpc(DomainName = "ticket", UriSettingsKey = "trac")]
public interface ITicket
	object[] get(int id);
	[RpcMethod(DomainName="ticket.resolution", MethodName="getAll")]
	string[] GetResolutions();

Happy coding!