Getting Started. (ASP.net Http Handler)

1) Create a new ASP.NET Web Application.

2) Use NuGet to Download the most recent JSON-RPC.NET Asp.Net package.

3) Edit the web.config file and add a http handler.
For Casini (ASP.NET development server) and IIS6 add the following to <system.web>
    <httpHandlers>
      <add type="AustinHarris.JsonRpc.Handlers.AspNet.JsonRpcHandler" verb="*" path="*.rpc"/>
    </httpHandlers>
For IIS 7+ add the following to <system.webServer>
    <handlers>
      <add name="jsonrpc" type="AustinHarris.JsonRpc.Handlers.AspNet.JsonRpcHandler" verb="*" path="*.rpc"/>
    </handlers>

5) Create a new class that inherits from JsonRpcService. Ex:
    public class HelloWorldService: JsonRpcService{
    }

6) Inside your new class create a new method, and attribute it with [JsonRpcMethod].
        [JsonRpcMethod]
        private string helloWorld(string message){
            return "Hello World "+ message;
        }

7) In Global.asax.cs add a new static member of your new service class type. Ex:
public class Global : System.Web.HttpApplication {
    private static HelloWorldService service = new HelloWorldService();
}

8) Test it. POST a JSON-RPC request to /json.rpc. Ex:
POST http://localhost:49718/json.rpc HTTP/1.1
User-Agent: Fiddler
Content-Type: Application/Json-Rpc
Host: localhost:49718
Content-Length: 62

{"method": "helloWorld", "params": ["Hello World"], "id": 1  }

And you should receive a response. Ex:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 29 Aug 2011 05:21:22 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 58
Connection: Close

{"Result":"Hello World Hello World","Error":null,"Id":"1"}

Last edited Sep 19, 2012 at 4:33 AM by AustinHarris, version 1

Comments

No comments yet.