public string Post(HttpRequestMessage Request) { try { if (Request != null) { var Responsedata = Request.Content.ReadAsStringAsync().Result; string keyValue = ConfigurationManager.AppSettings["keyValue"].ToString(); string IVValue = ConfigurationManager.AppSettings["IVValue"].ToString(); string data = EncryptionDecryptorTripleDES.Decryption(Responsedata, keyValue, IVValue); LoginViewModel objVM = new JavaScriptSerializer().Deserialize <LoginViewModel>(data); var val = LoginBL.ValidateLoginUser(objVM.Username, objVM.Password); string SerializeData = JsonConvert.SerializeObject(val); byte[] buffer = EncryptionDecryptorTripleDES.Encryption(SerializeData, keyValue, IVValue); return(Convert.ToBase64String(buffer)); } else { return("Failed"); } } catch (Exception) { throw; } }
/// <summary> /// //Method is use to Validate User Credentials from Web Server Using WEB API /// </summary> /// <param name="Username"></param> /// <param name="Password"></param> public void ValidateUserandGetResponse(string Username, string Password) { try { UserLogin objvm = new UserLogin() { Username = Username, Password = EncryptandDecryptAES.Encrypt(Password) }; ShareObject.Username = Username; using (var client = new WebClient()) { string ClientToken = ConfigurationManager.AppSettings["CLientIDToken"].ToString(); string keyValue = ConfigurationManager.AppSettings["keyValue"].ToString(); string IVValue = ConfigurationManager.AppSettings["IVValue"].ToString(); Uri URI = new Uri(ConfigurationManager.AppSettings["LoginURI"].ToString()); client.Headers.Add("Content-Type:application/json"); client.Headers.Add("APIKEY", GenerateToken.CreateToken(Username, ClientToken, DateTime.Now.Ticks)); client.Headers.Add("Accept:application/json"); client.UploadStringCompleted += new UploadStringCompletedEventHandler(Callback); string SerializeData = JsonConvert.SerializeObject(objvm); byte[] buffer = EncryptionDecryptorTripleDES.Encryption(SerializeData, keyValue, IVValue); client.UploadStringAsync(URI, Convert.ToBase64String(buffer)); } } catch (Exception) { throw; } }
/// <summary> /// Method takes Product object as input for Pushing Data on Web Server /// </summary> /// <param name="Product"></param> public void DataPusher(Product Product) { try { using (var client = new WebClient()) { string ClientToken = ConfigurationManager.AppSettings["CLientIDToken"].ToString(); Uri URI = new Uri(ConfigurationManager.AppSettings["LiveURI"].ToString()); client.Headers.Add("Content-Type:application/json"); client.Headers.Add("Accept:application/json"); //Token APIKEY client.Headers.Add("APIKEY", GenerateToken.CreateToken(ShareObject.Username, ClientToken, DateTime.Now.Ticks)); //Setting Call back method client.UploadStringCompleted += new UploadStringCompletedEventHandler(Callback); //key and IV string keyValue = ConfigurationManager.AppSettings["keyValue"].ToString(); string IVValue = ConfigurationManager.AppSettings["IVValue"].ToString(); //Serializing Object string SerializeData = JsonConvert.SerializeObject(Product); //Encrypting Serialized Object byte[] buffer = EncryptionDecryptorTripleDES.Encryption(SerializeData, keyValue, IVValue); //Converting bytes To Base64String and then Upload data client.UploadStringAsync(URI, Convert.ToBase64String(buffer)); } } catch (Exception) { throw; } }