Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created June 24, 2013 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/5851501 to your computer and use it in GitHub Desktop.
Save atifaziz/5851501 to your computer and use it in GitHub Desktop.
// https://groups.google.com/forum/#!topic/jayrock/WbWpudBQWD8
using System;
using System.Collections;
using System.Collections.Generic;
using Jayrock.Json;
using Jayrock.JsonRpc;
using Jayrock.JsonRpc.Web;
using Jayrock.Services;
static class Program
{
static void Main()
{
JsonRpcDispatcherFactory.Current = s => new JsonRpcDispatcher(s);
var service = new MyService();
var dispatcher = JsonRpcDispatcherFactory.CreateDispatcher(service);
Console.WriteLine(dispatcher.Process("{ id: 1, method: cities }"));
}
class MyService : JsonRpcHandler
{
[JsonRpcMethod(Idempotent = true)]
public IEnumerable<string> Cities()
{
return new[] { "London", "Zurich", "Paris", "New York" };
}
}
class JsonRpcDispatcher : Jayrock.JsonRpc.JsonRpcDispatcher
{
public JsonRpcDispatcher(IService service) : base(service) {}
protected override void WriteResponse(IDictionary response, JsonWriter output)
{
// TODO handle case where response is an error
JsonExporter(response["result"], output);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment