Tuesday, May 1st, 2007

Jayrock: JSON and JSON-RPC for .NET

Category: .NET, JavaScript, JSON

Jayrock is a modest and an open source implementation of JSON and JSON-RPC for the Microsoft .NET Framework, including ASP.NET. What’s so modest about it? Well, modest as in plain and basic and no work of genius.

A developer creates a helloworld.ashx that contains your server side logic:

  1. < %@ WebHandler Class="JayrockWeb.HelloWorld" %>
  2.  
  3. namespace JayrockWeb
  4. {
  5.     using System;
  6.     using System.Web;
  7.     using Jayrock.Json;
  8.     using Jayrock.JsonRpc;
  9.     using Jayrock.JsonRpc.Web;
  10.  
  11.     public class HelloWorld : JsonRpcHandler
  12.     {
  13.         [ JsonRpcMethod("greetings") ]
  14.         public string Greetings()
  15.         {
  16.             return "Welcome to Jayrock!";
  17.         }
  18.     }
  19. }

Then you can access the file asking for a proxy via helloworld.ashx?proxy and you will see a test page. From code you can now:

javascript

  1. var s = new HelloWorld();
  2.  
  3.     alert("sync:" + s.greetings());
  4.  
  5.     s.greetings(function(response) {
  6.       alert("async:" + response.result)
  7.     });

Nice and simple.

Posted by Dion Almaer at 5:34 am
2 Comments

+++--
3.4 rating from 42 votes

2 Comments »

Comments feed TrackBack URI

Another possible library for use with .NET would be http://www.newtonsoft.com/products/json/

I’ve succesfully used it in a commercial site, and it’s easy to work with and produces quality results, once you get your head around only serializing the stuff the client needs, instead of serializing EVERYTHING.

http://json.org has lot’s of good info.

Comment by Morgan Roderick — May 1, 2007

Neat.

Comment by Rotev — May 7, 2007

Leave a comment

You must be logged in to post a comment.