forked from Astn/JSON-RPC.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestService.cs
More file actions
138 lines (118 loc) · 3.93 KB
/
TestService.cs
File metadata and controls
138 lines (118 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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<string> testFloat(float input)
{
return new List<string>() { "one", "two", "three", input.ToString() };
}
[JsonRpcMethod]
private List<string> testInt(int input)
{
return new List<string>() { "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<string> testSimpleString(string input)
{
return new List<string>() { "one", "two", "three", input };
}
[JsonRpcMethod]
private List<string> testThrowingException(string input)
{
throw new Exception("Throwing Exception");
return new List<string>() { "one", "two", "three", input };
}
public class CustomString
{
public string str;
}
[JsonRpcMethod("testCustomString")]
private List<string> testCustomString(CustomString input)
{
return new List<string>() { "one", "two", "three", input.str };
}
private class recursiveClass
{
public recursiveClass Nested1 { get; set; }
public int Value1 { get; set; }
}
}
}