namespace testwebapi { /// <summary> /// Summary description for testwebapi /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class testwebapi: System.Web.Services.WebService { public class AuthHeader : SoapHeader { public string Username; public string Password; } public AuthHeader Authentication; [SoapHeader("Authentication", Required = true)] [WebMethod(Description = "WebMethod authentication testing")] public string SensitiveData() { //Do our authentication //this can be via a database or whatever if (Authentication.Username == ConfigurationManager.AppSettings["ff_username"] && Authentication.Password == ConfigurationManager.AppSettings["ff_password"]) { //Do your thing string success = ""; success = "{\"status\": \"test web api security.\"}"; this.Context.Response.ContentType = "application/json; charset=utf-8"; this.Context.Response.Write(success); return ""; } else { //if authentication fails return null; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)