protected override void OnLoad(EventArgs e) { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Clear(); base.OnLoad(e); string action = Request.QueryString["a"]; if (!string.IsNullOrEmpty(action)) { if (string.Equals(action, "util", StringComparison.OrdinalIgnoreCase)) { string type = Request.QueryString["t"]; if (!string.IsNullOrEmpty(type)) { if ("Escape".Equals(type)) { Response.Write("<textarea id='box' style='width:800px; height:500px;'></textarea><br /><script>var b = document.getElementById('box');</script><input type='button' onmousedown='box.value = unescape(box.value);' value='UnEscape' /><input type='button' onmousedown='box.value = escape(box.value);' value='Escape' />"); Response.End(); } } } JsRequest r = new JsRequest(); string[] actions = action.Split(','); foreach (string a in actions) { Method m = r.AddMethod(a); if (!string.IsNullOrEmpty(a)) { string param = Request.QueryString[a]; if (!string.IsNullOrEmpty(param)) { string[] args = param.Split(','); foreach (string i in args) { m.AddParam(i); } } } } HandleJsRequest(r); } string xml = Request.Form["xml"]; if (!string.IsNullOrEmpty(xml)) { JsRequest r = xml.FromXml<JsRequest>(); HandleJsRequest(r); } else if (string.IsNullOrEmpty(action)) { JsRequest r = new JsRequest(); r.Methods.Add(new Method { Name = "GetData" }); r.Methods[0].Params.Add(new Param { Name = "Arg1", Value = "a" }); r.Methods[0].Params.Add(new Param { Name = "Arg2", Value = "b" }); Response.Write(r.ToXml()); } AuthCodePage.Update(); Response.End(); }
private void ProcessNormalRequest(string action) { JsRequest r = new JsRequest(); string[] actions = action.Split(','); foreach (string a in actions) { Method m = r.AddMethod(a); if (!string.IsNullOrEmpty(a)) { string param = Request.QueryString[a]; if (!string.IsNullOrEmpty(param)) { string[] args = param.Split(','); foreach (string i in args) { m.AddParam(i); } } } } HandleJsRequest(r); }
private InvokeResult InvokeMethod(JsRequest r, MethodInfo mi) { InvokeResult rlt = new InvokeResult(); try { if (mi != null) { mi.ValidateServiceMethod(rlt); r.AddMethod(mi.Name); if (mi.ReturnType == typeof (void)) { if (Params != null && Params.Length > 0) { object[] args = Params.ConvertType(0, mi.GetParameters()); mi.Invoke(this, args); r.Methods[0].MethodReturnValue = null; } else { mi.Invoke(this, null); r.Methods[0].MethodReturnValue = null; } } else { object rv = null; if (Params != null && Params.Length > 0) { object[] args = Params.ConvertType(0, mi.GetParameters()); rv = mi.Invoke(this, args); } else { rv = mi.Invoke(this, null); } r.Methods[0].MethodReturnValue = rv; if (rv is ResultBase) { ResultBase result = (ResultBase)rv; if (!result.IsNoException) { r.SetException(result.LastError, mi.Name); } } } } else { throw new ArgumentNullException(ServerErrorCode.MethodNull); } } catch (Exception ex) { rlt.LastError = ex; if (mi != null) { r.SetException(ex, mi.Name); } else { r.SetException(ex); } } return rlt; }
private void HandleRestfulRequest(HttpContext context) { string method = context.Request.HttpMethod; JsRequest r = new JsRequest(); Method m = r.AddMethod(method); if (method.IndexOf("get", StringComparison.OrdinalIgnoreCase) >= 0) { m.MethodReturnValue = Get(context); } else if (method.IndexOf("post", StringComparison.OrdinalIgnoreCase) >= 0) { m.MethodReturnValue = Post(context); } else if (method.IndexOf("put", StringComparison.OrdinalIgnoreCase) >= 0) { m.MethodReturnValue = Put(context); } else if (method.IndexOf("delete", StringComparison.OrdinalIgnoreCase) >= 0) { m.MethodReturnValue = Delete(context); } else { r.SetException(new ArgumentException(ServerErrorCode.InvalidHttpMethod)); } OutputResponse(r); }