http://jsonrpc2.codeplex.com/或https://github.com/Astn/JSON-RPC.NET/wiki/Getting-Started-%28Asp.Net%29 標簽: <無>
代碼片段

using system; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AustinHarris.JsonRpc; /****************************************************************************************************************** * * * 說 明: RPC服務(版本:version1.0.0) * 作 者:李朝強 * 日 期:2015/05/19 * 修 改: * 參 考:http://my.oschina.net/lichaoqiang/ * 備 註:暫無... * * * ***************************************************************************************************************/ namespace JsonRpc.Service { /// <summary> /// 服務 /// </summary> public class ExampleCalculatorService : JsonRpcService { /// <summary> /// 加法運算 /// </summary> /// <param name="l"></param> /// <param name="r"></param> /// <returns></returns> [JsonRpcMethod] private double add(double l, double r) { return l + r; } /// <summary> /// /// </summary> /// <returns></returns> [JsonRpcMethod] private string say(string word) { return word; } /// <summary> /// /// </summary> /// <returns></returns> [JsonRpcMethod("OpenOSC")] private OSC OpenOSC() { OSC osc = new OSC("開源中國", "http://www.oschina.net"); return osc; } } }

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AustinHarris.JsonRpc; /****************************************************************************************************************** * * * 說 明: JsonRpc.Net for Console(版本:Version1.0.0) * 作 者:李朝強 * 日 期:2015/05/19 * 修 改: * 參 考:http://my.oschina.net/lichaoqiang/ * 備 註:暫無... * * * ***************************************************************************************************************/ namespace JsonRpcApp { class Program { /// <summary> /// 靜態成員:服務 /// </summary> static object[] services = new object[] { new JsonRpc.Service.ExampleCalculatorService() }; /// <summary> /// 入口 /// </summary> /// <param name="args"></param> static void Main(string[] args) { var rpcResultHandler = new AsyncCallback(_ => Console.WriteLine(((JsonRpcStateAsync)_).Result)); for (string line = Console.ReadLine(); !string.IsNullOrEmpty(line); line = Console.ReadLine()) { var async = new JsonRpcStateAsync(rpcResultHandler, null); async.JsonRpc = line; JsonRpcProcessor.Process(async); } } } }
<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="false"/> <handlers> <add name="jsonrpc" type="AustinHarris.JsonRpc.Handlers.AspNet.JsonRpcHandler" verb="*" path="*.rpc" /> </handlers> </system.webServer>
Tags: public 標簽 知識
文章來源: