diff --git a/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj b/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj deleted file mode 100644 index 3470e2c..0000000 --- a/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj +++ /dev/null @@ -1,77 +0,0 @@ - - - - - Debug - AnyCPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB} - Library - Properties - AustinHarris.JsonRpc.AspNet - AustinHarris.JsonRpc.AspNet - v4.0 - 512 - SAK - SAK - SAK - SAK - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll - True - - - - - - - - - - - - - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/AustinHarris.JsonRpc.AspNet/JsonRpcHandler.cs b/AustinHarris.JsonRpc.AspNet/JsonRpcHandler.cs deleted file mode 100644 index 6a38c39..0000000 --- a/AustinHarris.JsonRpc.AspNet/JsonRpcHandler.cs +++ /dev/null @@ -1,16 +0,0 @@ -using AustinHarris.JsonRpc.AspNet; - -namespace AustinHarris.JsonRpc.Handlers.AspNet -{ - /// - /// Used default SessionId - /// For routing use JsonRpcHandlerBase - /// - public class JsonRpcHandler : JsonRpcHandlerBase - { - protected override string GetSessionId() - { - return Handler.DefaultSessionId(); - } - } -} \ No newline at end of file diff --git a/AustinHarris.JsonRpc.AspNet/JsonRpcHandlerBase.cs b/AustinHarris.JsonRpc.AspNet/JsonRpcHandlerBase.cs deleted file mode 100644 index 8d61777..0000000 --- a/AustinHarris.JsonRpc.AspNet/JsonRpcHandlerBase.cs +++ /dev/null @@ -1,138 +0,0 @@ -using System; -using System.IO; -using System.IO.Compression; -using System.Text; -using System.Web; - -namespace AustinHarris.JsonRpc.AspNet -{ - public abstract class JsonRpcHandlerBase : IHttpAsyncHandler - { - #region Fields - /// - /// UTF8 Encoding without BOM. - /// - private static readonly Encoding Utf8Encoding = new UTF8Encoding(false); - - protected abstract string GetSessionId(); - #endregion - - #region IHttpHandler Members - - public bool IsReusable - { - get { return true; } - } - - public void ProcessRequest(HttpContext context) - { - // not used - } - - #endregion - - #region IHttpAsyncHandler Members - - /// - /// Initiates an asynchronous call to the HTTP handler. - /// - /// An object that provides references to intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests. - /// The to call when the asynchronous method call is complete. If is null, the delegate is not called. - /// Any extra data needed to process the request. - /// - /// An that contains information about the status of the process. - /// - public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) - { - var async = new JsonRpcStateAsync(cb, context); - async.JsonRpc = GetJsonRpcString(context.Request); - JsonRpcProcessor.Process(GetSessionId(),async, context.Request); - return async; - } - - private static string GetJsonRpcString(System.Web.HttpRequest request) - { - string json = string.Empty; - if (request.RequestType == "GET") - { - json = request.Params["jsonrpc"] ?? string.Empty; - } - else if (request.RequestType == "POST") - { - if (request.ContentType == "application/x-www-form-urlencoded") - { - json = request.Params["jsonrpc"] ?? string.Empty; - } - else - { - json = new StreamReader(request.InputStream).ReadToEnd(); - } - } - return json; - } - - /// - /// Provides an asynchronous process End method when the process ends. - /// - /// An that contains information about the status of the process. - public void EndProcessRequest(IAsyncResult result) - { - var state = result as JsonRpcStateAsync; - if (state == null) return; - - var stateResult = state.Result; - var callback = ((HttpContext)state.AsyncState).Request.Params["callback"]; - if (!string.IsNullOrWhiteSpace(callback)) - { - stateResult = string.Format("{0}({1})", callback, stateResult); - } - - // try to compress the response data. - // fix me: compression filters in IHttpModule always failed for IHttpAsyncHandler - CompressResponseIfPossible(((HttpContext)state.AsyncState).Request, ((HttpContext)state.AsyncState).Response, stateResult, Utf8Encoding); - } - - #endregion - - #region Utility methods - - /// - /// Transfer the result data compressed when the client accepts gzip. - /// - /// A HttpRequest object that represents the HTTP request. - /// A HttpResponse object that represents the HTTP response to be sent to the client. - /// The string data to be sent to the client. - /// The Encoding to be used to encode as the result. - static void CompressResponseIfPossible(HttpRequest request, HttpResponse response, String result, Encoding encoding) - { - response.ContentType = "application/json-rpc"; - string acceptEncoding = request.Headers["Accept-Encoding"]; - if (acceptEncoding != null && acceptEncoding.Contains("gzip")) - { - //response.Headers.Remove("Content-Encoding"); - response.AddHeader("Content-Encoding", "gzip"); - - using (var gstream = new GZipStream(response.OutputStream, CompressionMode.Compress)) - using (var writer = new StreamWriter(gstream, encoding)) - { - writer.Write(result); - writer.Flush(); - } - } - else - { - using (StreamWriter writer = new StreamWriter(response.OutputStream, encoding)) - { - writer.Write(result); - writer.Flush(); - } - } - - response.End(); - } - - - #endregion - - } -} diff --git a/AustinHarris.JsonRpc.AspNet/Properties/AssemblyInfo.cs b/AustinHarris.JsonRpc.AspNet/Properties/AssemblyInfo.cs deleted file mode 100644 index 6ba1c02..0000000 --- a/AustinHarris.JsonRpc.AspNet/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Json-Rpc.Net ASP.net")] -[assembly: AssemblyDescription("ASP.net Handler for JsonRpc.Net")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("AustinHarris.JsonRpc.AspNet")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("b4fdaac3-c43c-4ba1-8a67-fab33b3ec7e6")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.2.0")] -[assembly: AssemblyFileVersion("1.0.2.0")] diff --git a/AustinHarris.JsonRpc.AspNet/packages.config b/AustinHarris.JsonRpc.AspNet/packages.config deleted file mode 100644 index 0fa4e01..0000000 --- a/AustinHarris.JsonRpc.AspNet/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/AustinHarris.JsonRpc.Client/AustinHarris.JsonRpc.Client.csproj b/AustinHarris.JsonRpc.Client/AustinHarris.JsonRpc.Client.csproj deleted file mode 100644 index c6cd7a9..0000000 --- a/AustinHarris.JsonRpc.Client/AustinHarris.JsonRpc.Client.csproj +++ /dev/null @@ -1,92 +0,0 @@ - - - - Debug - AnyCPU - - - 2.0 - {03FF12D9-6027-4050-81AC-A90B0EA8F8EB} - Library - Properties - AustinHarris.JsonRpc.Client - AustinHarris.JsonRpc.Client - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - SAK - SAK - SAK - SAK - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - bin\WindowsPhone\ - TRACE - true - pdbonly - AnyCPU - prompt - false - false - - - - - False - ..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll - - - - 3.5 - - - ..\packages\Rx-Main.1.0.10621\lib\Net4\System.Reactive.dll - - - - - False - - - - - JsonRequest.cs - - - JsonResponse.cs - - - JsonResponseErrorObject.cs - - - - - - - - - - \ No newline at end of file diff --git a/AustinHarris.JsonRpc.Client/Properties/AssemblyInfo.cs b/AustinHarris.JsonRpc.Client/Properties/AssemblyInfo.cs deleted file mode 100644 index 7a56369..0000000 --- a/AustinHarris.JsonRpc.Client/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("AustinHarris.JsonRpc.Client")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("AustinHarris.JsonRpc.Client")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("f0ae27be-5b53-491d-a670-bae0ca4a1a7a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AustinHarris.JsonRpc.Client/client.cs b/AustinHarris.JsonRpc.Client/client.cs deleted file mode 100644 index 4992a81..0000000 --- a/AustinHarris.JsonRpc.Client/client.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using Newtonsoft.Json.Linq; -using AustinHarris.JsonRpc; -using System.Linq; -using System.Reactive.Linq; -using System.Reactive.Subjects; -using System.Reactive.Concurrency; -using System.Diagnostics; - -namespace AustinHarris.JsonRpc -{ - public class JsonRpcClient - { - private static object idLock = new object(); - private static int id = 0; - public Uri ServiceEndpoint = null; - public JsonRpcClient(Uri serviceEndpoint) - { - ServiceEndpoint = serviceEndpoint; - } - - private static Stream CopyAndClose(Stream inputStream) - { - const int readSize = 256; - byte[] buffer = new byte[readSize]; - MemoryStream ms = new MemoryStream(); - - int count = inputStream.Read(buffer, 0, readSize); - while (count > 0) - { - ms.Write(buffer, 0, count); - count = inputStream.Read(buffer, 0, readSize); - } - ms.Position = 0; - inputStream.Close(); - return ms; - } - - public IObservable> Invoke(string method, object arg, IScheduler scheduler) - { - var req = new AustinHarris.JsonRpc.JsonRequest() - { - Method = method, - Params = new object[] { arg } - }; - return Invoke(req, scheduler); - } - - public IObservable> Invoke(string method, object[] args, IScheduler scheduler) - { - var req = new AustinHarris.JsonRpc.JsonRequest() - { - Method = method, - Params = args - }; - return Invoke(req,scheduler); - } - - public IObservable> Invoke(JsonRequest jsonRpc, IScheduler scheduler) - { - var res = Observable.Create>((obs) => - scheduler.Schedule(()=>{ - - WebRequest req = null; - try - { - int myId; - lock (idLock) - { - myId = ++id; - } - jsonRpc.Id = myId.ToString(); - req = HttpWebRequest.Create(new Uri(ServiceEndpoint, "?callid=" + myId.ToString())); - req.Method = "Post"; - req.ContentType = "application/json-rpc"; - } - catch (Exception ex) - { - obs.OnError(ex); - } - - var ar = req.BeginGetRequestStream(new AsyncCallback((iar) => - { - HttpWebRequest request = null; - - try - { - request = (HttpWebRequest)iar.AsyncState; - var stream = new StreamWriter(req.EndGetRequestStream(iar)); - var json = Newtonsoft.Json.JsonConvert.SerializeObject(jsonRpc); - stream.Write(json); - - stream.Close(); - } - catch (Exception ex) - { - obs.OnError(ex); - } - - var rar = req.BeginGetResponse(new AsyncCallback((riar) => - { - JsonResponse rjson = null; - string sstream = ""; - try - { - var request1 = (HttpWebRequest)riar.AsyncState; - var resp = (HttpWebResponse)request1.EndGetResponse(riar); - - using (var rstream = new StreamReader(CopyAndClose(resp.GetResponseStream()))) - { - sstream = rstream.ReadToEnd(); - } - - rjson = Newtonsoft.Json.JsonConvert.DeserializeObject>(sstream); - } - catch (Exception ex) - { - Debug.WriteLine(ex.Message); - Debugger.Break(); - } - - if (rjson == null) - { - if (!string.IsNullOrEmpty(sstream)) - { - JObject jo = Newtonsoft.Json.JsonConvert.DeserializeObject(sstream) as JObject; - obs.OnError(new Exception(jo["Error"].ToString())); - } - else - { - obs.OnError(new Exception("Empty response")); - } - } - - obs.OnNext(rjson); - obs.OnCompleted(); - }), request); - }), req); - })); - - return res; - } - - } -} diff --git a/AustinHarris.JsonRpc.Client/packages.config b/AustinHarris.JsonRpc.Client/packages.config deleted file mode 100644 index 17e45de..0000000 --- a/AustinHarris.JsonRpc.Client/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 17a2936..1f4b2e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ behaviour: a breaking change to either means a new major version. - The `JsonSerializerSettings` overloads of `JsonRpcProcessor.Process*` (pass a serializer instead; the Newtonsoft package has settings-based helpers). - Json.NET attributes on `JsonRequest`, `JsonResponse` and `JsonRpcException`. +- The 1.x projects that 2.0 did not build: `AustinHarris.JsonRpc.Client`, `AustinHarris.JsonRpc.AspNet`, the Windows Phone 7 client, `JsonRpcTest` and `TestClient`. They were .NET Framework 4.0 `packages.config` projects outside the solution, referencing packages with open advisories; their source is in the git history before 2.0. ### Fixed diff --git a/JsonRpcTest/Global.asax b/JsonRpcTest/Global.asax deleted file mode 100644 index 7632cd0..0000000 --- a/JsonRpcTest/Global.asax +++ /dev/null @@ -1 +0,0 @@ -<%@ Application Codebehind="Global.asax.cs" Inherits="JsonRpcTest.Global" Language="C#" %> diff --git a/JsonRpcTest/Global.asax.cs b/JsonRpcTest/Global.asax.cs deleted file mode 100644 index 92fb31b..0000000 --- a/JsonRpcTest/Global.asax.cs +++ /dev/null @@ -1,43 +0,0 @@ -using AustinHarris.JsonRpc; -using System; - -namespace JsonRpcTest{ - public class Global : System.Web.HttpApplication { - static object[] services = new object[] { - new TestServer.HelloWorldService(), - new TestServer.TestService(), - - }; - protected void Application_Start(object sender, EventArgs e) { - AustinHarris.JsonRpc.Config.SetErrorHandler(OnJsonRpcException); - Config.SetPreProcessHandler(new PreProcessHandler(PreProcess)); - } - - private AustinHarris.JsonRpc.JsonRpcException OnJsonRpcException(AustinHarris.JsonRpc.JsonRequest rpc, AustinHarris.JsonRpc.JsonRpcException ex) - { - return ex; - } - - private JsonRpcException PreProcess(JsonRequest rpc, object context) - { - // Useful for logging or authentication using the context. - - if(!string.Equals(rpc.Method, "RequiresCredentials",StringComparison.CurrentCultureIgnoreCase)) - return null; - - // If this is using the ASP.Net handler then the context will contain the httpRequest - // you could use that for cookies or IP authentication. - - // Here we will just check that the first parameter is a magic Key - // DO NOT do this type of thing in production code. You would be better just checking the parameter inside the JsonRpcMethod. - var j = rpc.Params as Newtonsoft.Json.Linq.JArray; - if (j == null - || j[0] == null - || j[0].Type != Newtonsoft.Json.Linq.JTokenType.String - || !string.Equals(j[0].ToString(), "GoodPassword", StringComparison.CurrentCultureIgnoreCase) - ) return new JsonRpcException(-2, "This exception was thrown using: JsonRpcTest.Global.PreProcess, Not Authenticated", null); - - return null; - } - } -} \ No newline at end of file diff --git a/JsonRpcTest/HelloWorldService.cs b/JsonRpcTest/HelloWorldService.cs deleted file mode 100644 index e5a7547..0000000 --- a/JsonRpcTest/HelloWorldService.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace TestServer{ - using System; - using AustinHarris.JsonRpc; - - public class HelloWorldService: JsonRpcService{ - [JsonRpcMethod] - private string helloWorld(string message){ - return "Hello World "+ message; - } - } -} \ No newline at end of file diff --git a/JsonRpcTest/HttpGetExamples.html b/JsonRpcTest/HttpGetExamples.html deleted file mode 100644 index 4372a77..0000000 --- a/JsonRpcTest/HttpGetExamples.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - -

The methods being invoked can be found in TestService.cs

-

These examples use HTTP GET to make the JsonRpc request. I recommend Fiddler2 to peek at http traffic.

-

An example of a get request looks like:

-
-                  /json.rpc?jsonrpc={'method':'internal.echo','params':['Echo%20This'],'id':2}
-            
-
-
-
Request: -
-
- - -
- -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
Response:
- -
-
- - diff --git a/JsonRpcTest/Properties/AssemblyInfo.cs b/JsonRpcTest/Properties/AssemblyInfo.cs deleted file mode 100644 index 3b8f770..0000000 --- a/JsonRpcTest/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("JsonRpcTest")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("JsonRpcTest")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0f411817-d0c2-4bd8-b835-e8eb54d37a5f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/JsonRpcTest/TestServer.csproj b/JsonRpcTest/TestServer.csproj deleted file mode 100644 index c4aff2e..0000000 --- a/JsonRpcTest/TestServer.csproj +++ /dev/null @@ -1,138 +0,0 @@ - - - - - Debug - AnyCPU - - - 2.0 - {A1077F2C-62A2-4EF6-BDF3-FB6F539A90A9} - {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - JsonRpcTest - JsonRpcTest - v4.0 - false - SAK - SAK - SAK - SAK - - - - - 4.0 - - - - - - - true - full - false - bin\ - DEBUG;TRACE - prompt - 4 - AnyCPU - - - pdbonly - true - bin\ - TRACE - prompt - 4 - - - - - False - ..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - Designer - - - Web.config - - - Web.config - - - - - - Global.asax - - - - - - - {fffdebbc-93f5-4a22-9ec5-d86a4a792dbb} - AustinHarris.JsonRpc.AspNet - - - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} - AustinHarris.JsonRpc - - - - - - - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - - - - - - False - False - 49718 - / - http://localhost/TestSever - False - False - - - False - - - - - - \ No newline at end of file diff --git a/JsonRpcTest/TestService.cs b/JsonRpcTest/TestService.cs deleted file mode 100644 index e6947b7..0000000 --- a/JsonRpcTest/TestService.cs +++ /dev/null @@ -1,138 +0,0 @@ -namespace TestServer -{ - using System; - using System.Collections.Generic; - using AustinHarris.JsonRpc; - using Newtonsoft.Json.Linq; - - public class TestService: JsonRpcService - { - [JsonRpcMethod("internal.echo")] - private string Handle_Echo(string s) - { - return s; - } - - - [JsonRpcMethod] - private string myIp() - { - var req = JsonRpcContext.Current().Value as System.Web.HttpRequest; - if (req != null) - return req.UserHostAddress; - return "IP not available"; - } - - [JsonRpcMethod] - private string myUserAgent() - { - var req = JsonRpcContext.Current().Value as System.Web.HttpRequest; - if (req != null) - return req.UserAgent.ToString(); - return "hmm. no UserAgent"; - } - - [JsonRpcMethod("error1")] - private string devideByZero(string s) - { - var i = 0; - var j = 15; - return s + j / i; // This causes the framework to throw an exception - } - - [JsonRpcMethod("error2")] - private string throwsException(string s, ref JsonRpcException refException) - { - refException = new JsonRpcException(-1, "This exception was thrown using: ref JsonRpcException", null); - return s; - } - - [JsonRpcMethod("error3")] - private string throwsException2(string s) - { - throw new JsonRpcException(-27000, "This exception was thrown using: throw new JsonRpcException()", null); - return s; - } - - [JsonRpcMethod("error4")] - private string throwsException3(string s) - { - JsonRpcContext.SetException(new JsonRpcException(-27000, "This exception was thrown using: JsonRpcContext.Current().SetException()", null)); - return s; - } - - [JsonRpcMethod] - private string RequiresCredentials(string magicKey) - { - return "Passed Authentication"; - } - - [JsonRpcMethod] - private DateTime testDateTime() - { - return DateTime.Now; - } - - [JsonRpcMethod] - private recursiveClass testRecursiveClass() - { - var obj = new recursiveClass() { Value1 = 10, Nested1 = new recursiveClass() { Value1 = 5 } }; - //obj.Nested1.Nested1 = obj; - return obj; - } - - [JsonRpcMethod] - private JObject testArbitraryJObject(JObject input) - { - return input; - } - - [JsonRpcMethod] - private List testFloat(float input) - { - return new List() { "one", "two", "three", input.ToString() }; - } - - [JsonRpcMethod] - private List testInt(int input) - { - return new List() { "one", "two", "three", input.ToString() }; - } - - [JsonRpcMethod] - private object[] testMultipleParameters(string one, int two, float three, CustomString four) - { - return new object[] { one, two, three, four }; - } - - [JsonRpcMethod("testSimpleString")] - private List testSimpleString(string input) - { - return new List() { "one", "two", "three", input }; - } - - [JsonRpcMethod] - private List testThrowingException(string input) - { - throw new Exception("Throwing Exception"); - return new List() { "one", "two", "three", input }; - } - - public class CustomString - { - public string str; - } - - [JsonRpcMethod("testCustomString")] - private List testCustomString(CustomString input) - { - return new List() { "one", "two", "three", input.str }; - } - - private class recursiveClass - { - public recursiveClass Nested1 { get; set; } - public int Value1 { get; set; } - } - } -} \ No newline at end of file diff --git a/JsonRpcTest/Web.Debug.config b/JsonRpcTest/Web.Debug.config deleted file mode 100644 index 2c6dd51..0000000 --- a/JsonRpcTest/Web.Debug.config +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/JsonRpcTest/Web.Release.config b/JsonRpcTest/Web.Release.config deleted file mode 100644 index 4122d79..0000000 --- a/JsonRpcTest/Web.Release.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/JsonRpcTest/Web.config b/JsonRpcTest/Web.config deleted file mode 100644 index a577eb8..0000000 --- a/JsonRpcTest/Web.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/JsonRpcTest/packages.config b/JsonRpcTest/packages.config deleted file mode 100644 index 12fef57..0000000 --- a/JsonRpcTest/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/README.md b/README.md index 75d9f02..c1742e8 100644 --- a/README.md +++ b/README.md @@ -705,7 +705,7 @@ dotnet test AustinHarris.JsonRpcTestN The test suite runs its protocol cases once per serializer (built-in, Json.NET, System.Text.Json) plus the parser, dispatch, version-policy and Kestrel integration tests, on both `net8.0` and `net10.0`. Building a package project in Release produces its NuGet package in `bin/Release/`. The WebAssembly sample builds without the `wasm-tools` workload; add it for AOT. -`AustinHarris.JsonRpc.Client`, `AustinHarris.JsonRpc.AspNet`, `JsonRpcTest` and `TestClient` are 1.x projects that are still in the tree but outside the solution; nothing in 2.0 is built from them. +The 1.x projects that 2.0 does not build (`AustinHarris.JsonRpc.Client`, `AustinHarris.JsonRpc.AspNet`, the Windows Phone 7 client, `JsonRpcTest` and `TestClient`) are no longer in the tree. Their source is in the git history before 2.0, and the 1.x packages stay on NuGet. ### Charts diff --git a/TestClient/Properties/AssemblyInfo.cs b/TestClient/Properties/AssemblyInfo.cs deleted file mode 100644 index eea0cef..0000000 --- a/TestClient/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TestClient")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("TestClient")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("354ab9d1-3f99-4e35-a007-6dfeeac07cb1")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestClient/TestClient.csproj b/TestClient/TestClient.csproj deleted file mode 100644 index 93f7ddb..0000000 --- a/TestClient/TestClient.csproj +++ /dev/null @@ -1,82 +0,0 @@ - - - - Debug - AnyCPU - - - 2.0 - {FA27C906-3591-48A5-B180-646EA6521E3E} - Library - Properties - TestClient - TestClient - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - SAK - SAK - SAK - SAK - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - False - ..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll - - - - 3.5 - - - ..\packages\Rx-Main.1.0.10621\lib\Net4\System.Reactive.dll - - - - - False - - - - - - - - - - - - {03FF12D9-6027-4050-81AC-A90B0EA8F8EB} - AustinHarris.JsonRpc.Client - - - - - - - - \ No newline at end of file diff --git a/TestClient/UnitTest1.cs b/TestClient/UnitTest1.cs deleted file mode 100644 index fa0193a..0000000 --- a/TestClient/UnitTest1.cs +++ /dev/null @@ -1,715 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Net; -using System.Reactive.Concurrency; -using System.Reactive.Linq; -using System.Threading; -using AustinHarris.JsonRpc; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; -using System.Text.RegularExpressions; - -namespace TestClient -{ - //[TestClass] - public class UnitTest1 - { - Random r = null; - Uri remoteUri = new Uri("http://localhost.:49718/json.rpc"); - public UnitTest1() - { - r = new Random(Environment.TickCount); - } - - [TestMethod] - public void TestHelloWorld() - { - AutoResetEvent are = new AutoResetEvent(false); - var client = new AustinHarris.JsonRpc.JsonRpcClient(remoteUri); - var myObs = client.Invoke("helloWorld", "My Message", Scheduler.TaskPool); - - using (myObs.Subscribe( - onNext: _ => - { - Console.WriteLine(_.Result); - Assert.IsTrue(_.Result == "Hello World My Message"); - }, - onError: _ => - { - Assert.Fail(); - are.Set(); - }, - onCompleted: () => are.Set() - )) - { - are.WaitOne(); - } - } - - private string getPrintableString(int len) - { - return new string(Enumerable.Range(0, r.Next(len)).Select(_ => (char)r.Next(32, 126)).ToArray()); - } - - private string getNonPrintableString(int len) - { - return new string(Enumerable.Range(0, r.Next(len)).Select(_ => (char)r.Next(0, 31)).ToArray()); - } - - private string getExtendedAsciiString(int len) - { - return new string(Enumerable.Range(0, r.Next(len)).Select(_ => (char)r.Next(0, 255)).ToArray()); - } - - [TestMethod] - public void TestArbitrary() - { - AutoResetEvent are = new AutoResetEvent(false); - var client = new AustinHarris.JsonRpc.JsonRpcClient(remoteUri); - var arbitrary = new Newtonsoft.Json.Linq.JObject(); - JObject r = null; - Exception e = null; - for (int i = 0; i < 10; i++) - { - arbitrary[getPrintableString(10)] = getPrintableString(20); - arbitrary[getNonPrintableString(10)] = getNonPrintableString(20); - arbitrary[getExtendedAsciiString(10)] = getExtendedAsciiString(20); - } - - var myObs = client.Invoke("testArbitraryJObject", arbitrary, Scheduler.TaskPool); - - using(myObs.Subscribe( - onNext: (jo) => - { - r = jo.Result; - }, - onError: _ => - { - e = _; - }, - onCompleted: () => are.Set() - )) - { - are.WaitOne(); - }; - - - Assert.IsTrue(r.ToString() == arbitrary.ToString()); - Assert.IsTrue(e == null); - } - - private JObject CreateArbitraryJObject() - { - var arbitrary = new Newtonsoft.Json.Linq.JObject(); - for (int i = 0; i < 1; i++) - { - arbitrary[getPrintableString(4)] = getPrintableString(4); - arbitrary[getNonPrintableString(4)] = getNonPrintableString(4); - arbitrary[getExtendedAsciiString(4)] = getExtendedAsciiString(4); - } - return arbitrary; - } - - [TestMethod] - public void TestRpcPerSecond() - { - // This test sometimes fails due to overloading - // the network buffer - var client = new AustinHarris.JsonRpc.JsonRpcClient(remoteUri); - var abjo = CreateArbitraryJObject(); - var limit = 50; - var passes = 5; - var requestStream = Observable.Generate(0, - i => i < limit, - i => i+1, - i => abjo - ); - for (int i = 0; i < passes; i++) - { - var tmr = Stopwatch.StartNew(); - SendRequestsAndWait(client, requestStream); - tmr.Stop(); - var perSecond = (decimal)limit * (1000 / (decimal)tmr.ElapsedMilliseconds); - Console.WriteLine("Pass{0} - {1} requests in : {2}ms for {3} requests per second", i, limit, tmr.ElapsedMilliseconds, (int)perSecond); - limit = limit * 2; - Thread.Sleep(200); - } - } - - [TestMethod] - public void TestNetworkBuffer() - { - // This will overflow the network buffer. - - //var client = new AustinHarris.JsonRpc.JsonRpcClient(remoteUri); - //var abjo = CreateArbitraryJObject(); - //var limit = 10000; - //var passes = 2; - //var requestStream = Observable.Generate(0, - // i => i < limit, - // i => i + 1, - // i => abjo - // ); - //for (int i = 0; i < passes; i++) - //{ - // var tmr = Stopwatch.StartNew(); - // SendRequestsAndWait(client, requestStream); - // tmr.Stop(); - // var perSecond = (decimal)limit * (1000 / (decimal)tmr.ElapsedMilliseconds); - // Console.WriteLine("Pass{0} - {1} requests in : {2}ms for {3} requests per second", i, limit, tmr.ElapsedMilliseconds, (int)perSecond); - // limit = limit * 2; - //} - } - - private void SendRequestsAndWait(JsonRpcClient client, IObservable requestStream) - { - // chaining is fun - var mre = new ManualResetEventSlim(false); - using ((from request in requestStream - select client.Invoke("testArbitraryJObject", request, Scheduler.TaskPool)) - .Merge() - .Subscribe( - onNext: _ => { /* do nothing and like it */ }, - onError: _ => {Debug.WriteLine(_.Message); mre.Set();}, - onCompleted: mre.Set)) - { - mre.Wait(); - } - } - - [TestMethod] - public void TestMetaData() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "?"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, null, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - are.WaitOne(); - - Assert.IsTrue(result != null); - var res = result.Result; - - } - - [TestMethod] - public void TestEcho() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "internal.echo"; - string input = "Echo this sucka"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input , Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - are.WaitOne(); - - Assert.IsTrue(result != null); - var res = result.Result; - Assert.IsTrue(res == input.ToString()); - } - - [TestMethod] - public void TestFloat() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "testFloat"; - float input = 7.1f; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input , Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - are.WaitOne(); - - Assert.IsTrue(result != null); - var res = result.Result; - Assert.IsTrue(res is IList); - var il = res as IList; - Assert.IsTrue(il[0] == "one"); - Assert.IsTrue(il[1] == "two"); - Assert.IsTrue(il[2] == "three"); - Assert.IsTrue(il[3] == input.ToString()); - Assert.IsTrue(il.Count == 4); - } - - [TestMethod] - public void TestInt() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "testInt"; - int input = 7; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input , Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - are.WaitOne(); - - Assert.IsTrue(result != null); - var res = result.Result; - Assert.IsTrue(res is IList); - var il = res as IList; - Assert.IsTrue(il[0] == "one"); - Assert.IsTrue(il[1] == "two"); - Assert.IsTrue(il[2] == "three"); - Assert.IsTrue(il[3] == input.ToString()); - Assert.IsTrue(il.Count == 4); - } - - [TestMethod] - public void TestSimpleString() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "testSimpleString"; - string input = "Hello"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - - are.WaitOne(); - - Assert.IsTrue(result != null); - var res = result.Result; - Assert.IsTrue(res is IList); - var il = res as IList; - Assert.IsTrue(il[0] == "one"); - Assert.IsTrue(il[1] == "two"); - Assert.IsTrue(il[2] == "three"); - Assert.IsTrue(il[3] == input.ToString()); - Assert.IsTrue(il.Count == 4); - } - - [TestMethod] - public void TestThrowingException() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "testThrowingException"; - string input = "Hello"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - - are.WaitOne(); - - Assert.IsTrue(result != null); - Assert.IsTrue(result.Result == null); - var res = result.Error; - Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); - if (res is JsonRpcException) - { - Assert.IsTrue(res.message == "Internal Error"); - } - } - - [TestMethod] - public void TestException() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "error1"; - string input = "Hello"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - - are.WaitOne(); - - Assert.IsTrue(result != null); - Assert.IsTrue(result.Result == null); - var res = result.Error; - Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); - if (res is JsonRpcException) - { - Assert.IsTrue(res.message == "Internal Error"); - } - } - - [TestMethod] - public void TestrefException() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "error2"; - string input = "Hello"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - - are.WaitOne(); - - Assert.IsTrue(result != null); - Assert.IsTrue(result.Result == null); - var res = result.Error; - Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); - if (res is JsonRpcException) - { - Assert.IsTrue(res.message == "This exception was thrown using: ref JsonRpcException"); - } - } - - [TestMethod] - public void TestThrowingJsonRpcException() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "error3"; - string input = "Hello"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - - are.WaitOne(); - - Assert.IsTrue(result != null); - Assert.IsTrue(result.Result == null); - var res = result.Error; - Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); - if (res is JsonRpcException) - { - Assert.IsTrue(res.message == "This exception was thrown using: throw new JsonRpcException()"); - } - } - - [TestMethod] - public void TestSettingJsonRpcExceptionWithContext() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "error4"; - string input = "Hello"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - - are.WaitOne(); - - Assert.IsTrue(result != null); - Assert.IsTrue(result.Result == null); - var res = result.Error; - Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); - if (res is JsonRpcException) - { - Assert.IsTrue(res.message == "This exception was thrown using: JsonRpcContext.Current().SetException()"); - } - } - - [TestMethod] - public void TestPreProcessingException() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "RequiresCredentials"; - string input = "BadPassword"; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - - are.WaitOne(); - - Assert.IsTrue(result != null); - Assert.IsTrue(result.Result == null); - var res = result.Error; - Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); - if (res is JsonRpcException) - { - Assert.IsTrue(res.message == "This exception was thrown using: JsonRpcTest.Global.PreProcess, Not Authenticated"); - } - } - - [TestMethod] - public void TestCustomString() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "testCustomString"; - var input = new { str = "Hello" }; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - are.WaitOne(); - - Assert.IsTrue(result != null); - var res = result.Result; - Assert.IsTrue(res is IList); - var il = res as IList; - Assert.IsTrue(il[0] == "one"); - Assert.IsTrue(il[1] == "two"); - Assert.IsTrue(il[2] == "three"); - Assert.IsTrue(il[3] == input.str); - Assert.IsTrue(il.Count == 4); - } - - [TestMethod] - public void TestMultipleParameters() - { - AutoResetEvent are = new AutoResetEvent(false); - var rpc = new JsonRpcClient(remoteUri); - string method = "testMultipleParameters"; - var anon = new CustomString { str = "Hello" }; - var input = new object[] {"one", 2, 3.3f, anon}; - JsonResponse result = null; - var myObs = rpc.Invoke(method, input, Scheduler.TaskPool); - - myObs.Subscribe( - onNext: _ => - { - result = _; - are.Set(); - }, - onError: _ => - { - are.Set(); - }, - onCompleted: () => { are.Set(); } - ); - - are.WaitOne(); - - Assert.IsTrue(result != null); - Assert.IsTrue(result.Result != null); - var res = result.Result; - Assert.IsTrue(res.Length == 4); - Assert.IsTrue((string)res[0] == (string)input[0]); - Assert.IsTrue((long)res[1] == (long)(int)input[1]); - Assert.IsTrue((double)res[2] == Double.Parse(input[2].ToString())); - Assert.IsTrue(Newtonsoft.Json.JsonConvert.DeserializeObject(res[3].ToString()).str == anon.str); - } - - [TestMethod] - public void TestJsonpWithHttpGet() - { - string method = "internal.echo"; - string input = "Echo this sucka"; - string id = "1"; - string callbackName = "myCallback"; - object[] parameters = new object[1]; - parameters[0] = input; - - JsonRequest jsonParameters = new JsonRequest() - { - Method = method, - Params = parameters, - Id = id - }; - var serailaizedParameters = Newtonsoft.Json.JsonConvert.SerializeObject(jsonParameters); - string uri = string.Format("{0}?jsonrpc={1}&callback={2}", remoteUri, serailaizedParameters, callbackName, id); - - WebRequest request = WebRequest.Create(uri); - WebResponse response = request.GetResponse(); - StreamReader reader = new StreamReader(response.GetResponseStream()); - - var regexPattern = callbackName + @"\({.*}\)"; - - var result = reader.ReadToEnd().Trim(); - - Assert.IsTrue(Regex.IsMatch(result, regexPattern)); - } - - [TestMethod] - public void TestJsonPWithHttpPost() - { - string method = "internal.echo"; - string input = "Echo this sucka"; - string id = "1"; - string callbackName = "myCallback"; - object[] parameters = new object[1]; - parameters[0] = input; - - JsonRequest jsonParameters = new JsonRequest() - { - Method = method, - Params = parameters, - Id = id - }; - - var serailaizedParameters = Newtonsoft.Json.JsonConvert.SerializeObject(jsonParameters); - var postData = string.Format("jsonrpc={0}&callback={1}", serailaizedParameters, callbackName); - - WebRequest request = WebRequest.Create(remoteUri); - request.ContentType = "application/x-www-form-urlencoded"; - request.Method = "POST"; - - byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postData); - request.ContentLength = bytes.Length; - - using (Stream stream = request.GetRequestStream()) - { - stream.Write(bytes, 0, bytes.Length); - stream.Close(); - } - - WebResponse response = request.GetResponse(); - StreamReader reader = new StreamReader(response.GetResponseStream()); - //myCallback({"jsonrpc":"2.0","result":"Echo this sucka","id":"1"}) - var regexPattern = callbackName + @"\({.*}\)"; - var result = reader.ReadToEnd().Trim(); - - Assert.IsTrue(Regex.IsMatch(result, regexPattern)); - } - public class CustomString - { - public string str; - } - } -} diff --git a/TestClient/jsonrpc.js b/TestClient/jsonrpc.js deleted file mode 100644 index 2f94d72..0000000 --- a/TestClient/jsonrpc.js +++ /dev/null @@ -1,214 +0,0 @@ -var SMD = { - "transport": "POST", - "envelope": "URL", - "target": "/json.rpc", - "additonalParameters": false, - "parameters": [], - "types": { - "0": { - "__name": "string" - }, - "1": { - "__name": "boolean" - }, - "2": { - "__name": "int32" - }, - "3": { - "__name": "int64" - }, - "4": { - "__name": "object" - }, - "5": { - "__name": "smdadditionalparameters[]", - "Length": 2, - "LongLength": 3, - "Rank": 2, - "SyncRoot": 4, - "IsReadOnly": 1, - "IsFixedSize": 1, - "IsSynchronized": 1 - }, - "6": { - "__name": "list`1", - "__genericArguments": [ - 0 - ], - "Capacity": 2, - "Count": 2, - "Item": 0 - }, - "7": { - "__name": "dictionary`2" - }, - "8": { - "__name": "type" - }, - "9": { - "__name": "smdadditionalparameters", - "ObjectType": 8, - "Name": 0, - "Type": 2, - "Default": 4 - }, - "10": { - "__name": "smdservice", - "transport": 0, - "envelope": 0, - "additionalParameters": 9, - "parameters": 5 - }, - "11": { - "__name": "iequalitycomparer`1", - "__genericArguments": [ - 0 - ] - }, - "12": { - "__name": "keycollection", - "__genericArguments": [ - 0, - 10 - ], - "Count": 2 - }, - "13": { - "__name": "valuecollection", - "__genericArguments": [ - 0, - 10 - ], - "Count": 2 - }, - "14": { - "__name": "dictionary`2", - "__genericArguments": [ - 0, - 10 - ], - "Comparer": 11, - "Count": 2, - "Keys": 12, - "Values": 13, - "Item": 10 - }, - "15": { - "__name": "smd", - "transport": 0, - "envelope": 0, - "target": 0, - "additonalParameters": 1, - "parameters": 5, - "TypeHashes": 6, - "Types": 7, - "Services": 14 - }, - "16": { - "__name": "single" - }, - "17": { - "__name": "customstring", - "str": 0 - } - }, - "services": { - "internal.echo": { - "transport": "POST", - "envelope": "JSON-RPC-2.0", - "additionalParameters": { - "__name": "returns", - "__type": 0, - "__default": null - }, - "parameters": [ - { - "__name": "s", - "__type": 0, - "__default": null - }, - null - ] - }, - "?": { - "transport": "POST", - "envelope": "JSON-RPC-2.0", - "additionalParameters": { - "__name": "returns", - "__type": 15, - "__default": null - }, - "parameters": [ - null - ] - }, - "testFloat": { - "transport": "POST", - "envelope": "JSON-RPC-2.0", - "additionalParameters": { - "__name": "returns", - "__type": 6, - "__default": null - }, - "parameters": [ - { - "__name": "input", - "__type": 16, - "__default": null - }, - null - ] - }, - "testInt": { - "transport": "POST", - "envelope": "JSON-RPC-2.0", - "additionalParameters": { - "__name": "returns", - "__type": 6, - "__default": null - }, - "parameters": [ - { - "__name": "input", - "__type": 2, - "__default": null - }, - null - ] - }, - "testSimpleString": { - "transport": "POST", - "envelope": "JSON-RPC-2.0", - "additionalParameters": { - "__name": "returns", - "__type": 6, - "__default": null - }, - "parameters": [ - { - "__name": "input", - "__type": 0, - "__default": null - }, - null - ] - }, - "testCustomString": { - "transport": "POST", - "envelope": "JSON-RPC-2.0", - "additionalParameters": { - "__name": "returns", - "__type": 6, - "__default": null - }, - "parameters": [ - { - "__name": "input", - "__type": 17, - "__default": null - }, - null - ] - } - } -}; diff --git a/TestClient/packages.config b/TestClient/packages.config deleted file mode 100644 index 17e45de..0000000 --- a/TestClient/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file