private void btnGet_Click(object sender, EventArgs e) { WebApiCall web = new WebApiCall(null); ApiCallArgument ar = new ApiCallArgument(txtServerUrl.Text, "Employee", false); ar.UseName = txtUser.Text; ar.Password = txtPass.Text; ar.Parameter = "Saiful"; // web.execute(ar, delegate(object p) { parseSingleEmployee(p); }); }
private void btnWebApi_Click(object sender, EventArgs e) { WebApiCall web = new WebApiCall(null); ApiCallArgument ar = new ApiCallArgument(txtServerUrl.Text, "Employee"); ar.UseName = txtUser.Text; ar.Password = txtPass.Text; // web.execute(ar, delegate(object p) { ResponseObject res = (ResponseObject)p; this.parseEmployee(res); return; }); }
// Match with Webservice // public IHttpActionResult post(Login obj) private async void executePOST(ApiCallArgument apiArgument) { try { HttpClient client = setup(); HttpResponseMessage response = await client.PostAsJsonAsync(apiArgument.ApiName, apiArgument.Parameter); HttpResponseMessage message = response.EnsureSuccessStatusCode(); // Get the URI of the created resource. var responseAsString = await response.Content.ReadAsStringAsync(); //var json = JsonConvert.DeserializeObject(responseAsString); //var responseAsType = JsonConvert.DeserializeObject<Employee>(responseAsString); //notifyObserver(new ResponseObject(responseAsType)); notifyObserver(new ResponseObject(responseAsString)); } catch (Exception e) { notifyObserver(new ResponseObject(e)); } }
private void btnLogin_Click(object sender, EventArgs e) { WebApiCall web = new WebApiCall(null); ApiCallArgument ar = new ApiCallArgument(txtServerUrl.Text, "Employee"); ar.UseName = txtUser.Text; ar.Password = txtPass.Text; ar.Parameter = new Login() { ID = txtUser.Text, Password = txtPass.Text }; // web.execute(ar, delegate(object p) { Employee emp = parseSingleEmployee(p); if (emp != null) { this.lblLoginID.Text = "Login as: " + emp.Name; } }); }
// http://localhost/Webservice/api/ // Match with GetAllEmployees // Pass User and Password in Authorization with Ecoding public override void execute(ApiCallArgument apiArgument, IDelegeateObserver observer) { this.url = apiArgument.Url; // Set the Notiifcation Observer.. this.mDelegeateObserver = observer; if (apiArgument.Parameter != null) { if (!apiArgument.POST) { executeGET(apiArgument); } else { executePOST(apiArgument); } } else { execute(apiArgument); } }
async void execute(ApiCallArgument apiArgument) { try { HttpClient client = setup(); // var authToken = Encoding.ASCII.GetBytes($"{apiArgument.UseName}:{apiArgument.Password}"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken)); // HttpResponseMessage response = await client.GetAsync(apiArgument.ApiName); HttpResponseMessage message = response.EnsureSuccessStatusCode(); var responseAsString = await response.Content.ReadAsStringAsync(); //var responseAsType = JsonConvert.DeserializeObject<Employee[]>(responseAsString); // // notifyObserver(new ResponseObject(responseAsType)); notifyObserver(new ResponseObject(responseAsString)); } catch (Exception e) { notifyObserver(new ResponseObject(e)); } }
abstract public void execute(ApiCallArgument apiArgument, IDelegeateObserver observer);