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:

 <appSettings>
     <add key="TracRpcUri" value="http://trac.mycompany.com/rpc" />
 </appSettings>

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 = result.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("http://trac.example.com/MyProject/login/rpc"), "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!

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.