Jayrock: JSON and JSON-RPC for .NET

Written by on May 1st, 2007 in Ajax News.

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:

C#:

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

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.  
  2.     var s = new HelloWorld();
  3.  
  4.     alert(”sync:” + s.greetings());
  5.  
  6.     s.greetings(function(response) {
  7.       alert(”async:” + response.result)
  8.     });
  9.  

Nice and simple.

Source: Ajaxian
Original Article: http://ajaxian.com/archives/jayrock-json-and-json-rpc-for-net

Leave a Reply

You must be logged in to post a comment.



Site Navigation