asp.net application invoke function demo using JSONRPC

Source: Internet
Author: User

Description: Using the JSON RPC call method in asp.net application to get the return value

1, vs new empty asp.net application, here. NET Framework Selection 4.0 +

2, download the latest version of the json-rpc.net asp.net package

Address:

http://jsonrpc2.codeplex.com/releases/view/100345

The json-rpc.net Server 1.0.3 is downloaded here

3, the introduction of the following two documents


4, at the same time to introduce


Otherwise, the project debug run will be wrong

Download Address http://json.codeplex.com/

The current project is introducing NET version 4.0

5, add the corresponding HTTP Handler in the Web.config file

Server (asp.net development server) or IIS6 add the following to the <system.web> tag

 

If the debug server is IIS 7 or above, add the following to the <system.webServer> tab

 

6, the next step is to create a new test class, and inherit from the Jsonrpcservice class, and introduce the corresponding namespace using Austinharris.jsonrpc;

public class helloworldservice:jsonrpcservice{
    }

7. Add a test method to [Jsonrpcmethod] in this class

[Jsonrpcmethod]
        private string HelloWorld (String message) {return
            ' Hello world ' + message;
        }

8. Add a Global.asax file and add a static member to it

public class Global:System.Web.HttpApplication {
    private static HelloWorldService service = new HelloWorldService () ;
}


9, now can be in our page through the JSON-RPC call method, add a Defualt page, and send a POST request to our JSON-RPC processing, here URL for your project actual URL and port number

<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Defualt.aspx.cs" inherits= "Testjsonrpc.defualt"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

10, click the Testjsonrpc button, return

{"JSONRPC": "2.0", "result": "Hello World Hello World", "Id": "1"}

This indicates that the function call was successful and that the return value was obtained


Article content from http://jsonrpc2.codeplex.com/more about JSONRPC content see here


The demo's C # code download address is attached click here to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.