Created
November 15, 2016 21:14
-
-
Save imcbride/8a659946d8c8e94b930d1341b63b8d15 to your computer and use it in GitHub Desktop.
This file contains 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 characters
using Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.DirectoryServices; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Services; | |
using System.Web.Script.Services; | |
/// <summary> | |
/// Summary description for RESTfulDirectory | |
/// </summary> | |
[WebService(Namespace = "http://tempuri.org/")] | |
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] | |
[ScriptService] | |
public class RESTfulDirectory : System.Web.Services.WebService { | |
public RESTfulDirectory () { | |
} | |
[WebMethod] | |
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] | |
public void Search(string q) { | |
Results results = new Results(); | |
results.directory = new List<Result>(); | |
if (q != null && q != "") | |
{ | |
// get the results from the directory | |
string search = "the LDAP search query"; | |
DataTable dt = Directory.query(search, "none"); | |
foreach (DataRow dr in dt.Rows) | |
{ | |
Result result = new Result(); | |
// populate the property fields | |
results.directory.Add(result); | |
} | |
} | |
string json = Newtonsoft.Json.JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); | |
HttpContext.Current.Response.Write(json); | |
} | |
} | |
public class Results | |
{ | |
public List<Result> directory; | |
} | |
public class Result | |
{ | |
// properties | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment