demo基于JSON-RPC.NET服务,演示了怎样在Web、Console应用中使用RPC服务。了解更多知识,可以访问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 * 修 改: * 参 考: * 备 注:暂无... * * * ***************************************************************************************************************/ namespace JsonRpc.Service { /// <summary> /// 服务 /// </summary> public class ExampleCalculatorService : JsonRpcService { /// <summary> /// 加法运算 /// </summary> /// <param></param> /// <param></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 * 修 改: * 参 考: * 备 注:暂无... * * * ***************************************************************************************************************/ namespace JsonRpcApp { class Program { /// <summary> /// 静态成员:服务 /// </summary> static object[] services = new object[] { new JsonRpc.Service.ExampleCalculatorService() }; /// <summary> /// 入口 /// </summary> /// <param></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 type="AustinHarris.JsonRpc.Handlers.AspNet.JsonRpcHandler" verb="*" path="*.rpc" /> </handlers> </system.webServer>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; using AustinHarris.JsonRpc; using JsonRpc.Service; /****************************************************************************************************************** * * * 说 明: 全局应用程序(版本:Version1.0.0) * 作 者:李朝强 * 日 期:2015/05/19 * 修 改: * 参 考: * 备 注:暂无... * * * ***************************************************************************************************************/ namespace JsonRpcAspNet { /// <summary> /// /// </summary> public class MvcApplication : System.Web.HttpApplication { /// <summary> /// 静态成员:服务 /// </summary> static object[] services = new object[] { new JsonRpc.Service.ExampleCalculatorService() }; /// <summary> /// /// </summary> protected void Application_Start() { //注意:如果出现404,请先注释以下代码后,再次尝试,关于原因,我们稍后再究其所以然。 //AreaRegistration.RegisterAllAreas(); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); //RouteConfig.RegisterRoutes(RouteTable.Routes); //BundleConfig.RegisterBundles(BundleTable.Bundles); } } }