Last active
December 19, 2015 23:59
-
-
Save atifaziz/6038424 to your computer and use it in GitHub Desktop.
Jayrock batch JSON-RPC requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://groups.google.com/forum/#!topic/jayrock/pDhGw_gwHJs | |
using System; | |
using Jayrock.Json; | |
using Jayrock.JsonRpc; | |
static class Program | |
{ | |
static void Main() | |
{ | |
using (var reader = JsonText.CreateReader(@" | |
[ | |
{ | |
id:3, | |
method:echoTest, | |
params:{ test : 'catty is here' } | |
}, | |
{ | |
id:4, | |
method:echoTest, | |
params:{ test : 'catty is here' } | |
}, | |
]")) | |
{ | |
if (!reader.MoveToContent()) | |
throw new Exception("Unexpected EOF."); | |
var dispatcher = JsonRpcDispatcherFactory.CreateDispatcher(new TestService()); | |
using (var writer = JsonText.CreateWriter(Console.Out)) | |
{ | |
if (reader.TokenClass == JsonTokenClass.Array) | |
{ | |
reader.Read(); | |
writer.WriteStartArray(); | |
while (reader.TokenClass != JsonTokenClass.EndArray) | |
dispatcher.Process(reader, writer); | |
writer.WriteEndArray(); | |
} | |
else | |
{ | |
dispatcher.Process(reader, writer); | |
} | |
} | |
} | |
} | |
} | |
public class TestService : JsonRpcService | |
{ | |
[JsonRpcMethod("echoTest")] | |
public object EchoTest(string test) | |
{ | |
return new { test }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment