Last active
December 24, 2015 07:28
Revisions
-
tufanbarisyildirim revised this gist
Sep 30, 2013 . 3 changed files with 20 additions and 36 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -91,4 +91,24 @@ public void ProcessRequest(HttpContext context) #endregion } public static class Extensions { public static string JsonSerialize(this object output) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Serialize(output); } } [Serializable] public class Result { public bool Success { get; set; } private string _message = ""; public string Message { get { return _message; } set { _message = value; } } } } -
tufanbarisyildirim created this gist
Sep 30, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Script; using System.Web.Script.Serialization; using System.Web.Script.Services; namespace ServiceTest { public static class Extensions { public static string JsonSerialize(this object output) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Serialize(output); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ServiceTest { [Serializable] public class Result { public bool Success { get; set; } private string _message = ""; public string Message { get { return _message; } set { _message = value; } } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,94 @@ using System; using System.Web; using System.Reflection; using System.Linq; using System.Collections.Specialized; using System.Collections.Generic; namespace ServiceTest { public class ServiceJsonAdapter : IHttpHandler { HttpRequest Request { get { return HttpContext.Current.Request; } } HttpResponse Response { get { return HttpContext.Current.Response; } } /// <summary> /// You will need to configure this handler in the web.config file of your /// web and register it with IIS before being able to use it. For more information /// see the following link: http://go.microsoft.com/?linkid=8101007 /// </summary> #region IHttpHandler Members public bool IsReusable { // Return false in case your Managed Handler cannot be reused for another request. // Usually this would be false in case you have some state information preserved per request. get { return true; } } public void ProcessRequest(HttpContext context) { // This is your real webservice instance. Example : MobileWebService.asmx MobileWebService MobService = new MobileWebService(); Type ServiceType = typeof(MobileWebService); NameValueCollection Collection; if (Request.HttpMethod == "POST") Collection = Request.Form; else Collection = Request.QueryString; String WebMethodName = Request["WebMethod"]; try { MethodInfo FoundMethod = ServiceType.GetMethod(WebMethodName); if (FoundMethod == null) throw new Exception("Metod Bulunamadı : " + WebMethodName); //string[] parameters = Collection.AllKeys.Where((x) => x != "WebMethod").SelectMany(Collection.GetValues, (k, v) => k).ToArray(); ParameterInfo[] RealParams = FoundMethod.GetParameters(); List<string> parameters = new List<string>(); foreach (ParameterInfo param in RealParams) { if (Collection.AllKeys.Contains(param.Name)) parameters.Add(Collection[param.Name]); else parameters.Add(String.Empty); } Response.Write(FoundMethod.Invoke(MobService, parameters.ToArray()).JsonSerialize()); } catch (Exception e) { Response.Write(new Result() { Success = false, Message = e.Message }.JsonSerialize()); } } #endregion } }