Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
Hayrom BlancoPosted Sep 29, 2019, 7:44 PM
Hi man, thanks for this tutorial, something is happening with the get method on the activity, is not working for me, i adapted your code to my project and it shows me a toast message saying "This request is invalid", and i don't know how to solve it, can you help me out please ? Here is my code for the Get: BtnGetEstudiante.Click += async delegate { EstudianteModel Estudiante = null; HttpClient Cliente = new HttpClient(); System.Net.ServicePointManager.Expect100Continue = false; Cliente.DefaultRequestHeaders.ExpectContinue = false; int GetTelefono = int.Parse(TxtGTelefono.Text); string Url = "http://matriculawebapitest.azurewebsites.net/api/Estudiante/GetTelefono"; Cliente.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var Resultado = await Cliente.GetAsync(Url); var json = await Resultado.Content.ReadAsStringAsync(); var Resp = JsonConvert.DeserializeObject<EstudianteModel>(json); try { if (Resultado.StatusCode == System.Net.HttpStatusCode.Accepted) { Estudiante = Newtonsoft.Json.JsonConvert.DeserializeObject<EstudianteModel>(json); Estudiante = Resp; } } catch (Exception Ex) { Toast.MakeText(this, Ex.ToString(), ToastLength.Long).Show(); } if (Estudiante != null) { TxtUpNombre.Text = Estudiante.Nombre; TxtUpApellido.Text = Estudiante.Apellidos; TxtUpFechaNacimiento.Text = Estudiante.FechaNacimiento.ToString(); TxtUpEnfermedad.Text = Estudiante.Enfermedades; TxtUpCorreo.Text = Estudiante.Correo; TxtUpTelefono.Text = Estudiante.Telefono.ToString(); } else { Toast.MakeText(this, json, ToastLength.Short).Show(); } }; And this is my API Get Method: [Route("api/Estudiante/{Telefono}")] public IHttpActionResult GetEstudianteByTelefono(int Telefono) { EstudianteModel Estudiante = null; using (var Ctx = new DataEntities()) { Estudiante = Ctx.TblEstudiantes .Where(S => S.Telefono == Telefono) .Select(S => new EstudianteModel() { Nombre = S.Nombre, Apellidos = S.Apellidos, FechaNacimiento = S.FechaNacimiento, Enfermedades = S.Enfermedades, Telefono = S.Telefono, Correo = S.Correo }).FirstOrDefault<EstudianteModel>(); } if (Estudiante == null) { return NotFound(); } return Ok(Estudiante); }
Mohanasundharam MuruganPosted Jan 25, 2019, 2:37 AM
Update the code for reteriving data from Firebase database in ListView using Xamarin Android
Sam MettenmeyerPosted Nov 28, 2018, 7:38 AM
Hello Ahsan, as this is the 4th tutorial, I followed all previous ones successfully. Unfortunately, within this video, you do something special in the beginning: you publish your service, so that it is online on a fixed url. But you do this with a already predefined profile (see 0:45): you just hit "publish" and everything's done. So how to create that profile? Can you show / tell how I can publish this service, so that I can consume it with my app? Best regards.
Rajib ArefinPosted Jul 1, 2018, 7:46 AM
Public IHttpActionResult Get_Feedback(int ID){ User user = null; try { user = db.Users.ToList().Where((u) => { return u.ID == ID; }).FirstOrDefault(); } catch (Exception r) { Debug.WriteLine(r.Message); } if (user == null) { return Ok("No record Found"); } else { var json = Newtonsoft.Json.JsonConvert.SerializeObject(user); return Json(json); } }
Rajib ArefinPosted Jul 1, 2018, 7:45 AM
Here is my get method:
Rajib ArefinPosted Jul 1, 2018, 4:16 AM
Json object converting error at the time of deserializingJul 1 2018 4:08 AM Assalamualaikum Sir, This is Leon from Bangladesh. I getting many help from your tutorial. A lot of thanks for that. Sir, here I am facing a problem when I m going to retrieve data from SQL Server using WEB Api and Xamarin Form. I can add data in SQL Server following your FEEDBACK tutorial in Youtube. But my GET method is not working properly, can u help me about that?? The Error is following given below: "Error converting value \"{\"ID\":5,\"EMail\":\"leonpowerpoint\",\"Subject\":\"The Sbj\",\"Messege\":\"Hellow Bro\"}\" to type 'FEEDBACK_APP.Feedback'. Path '', line 1, position 92." MY CODE IS: Feedback fb1 = null; HttpClient client = new HttpClient(); string Url = $"http://10.0.0.10:8083/api/Feedback?ID=" + "5".ToString(); var result = await client.GetAsync(Url); var json = await result.Content.ReadAsStringAsync(); var uri = new Uri(Url); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); try { fb1 = Newtonsoft.Json.JsonConvert.DeserializeObject<Feedback>(json); //HERE GETTING ERROR } catch(Exception r) { string st = r.Message; await DisplayAlert("Title", r.Message, "OK"); } if (fb1 == null) { } else { //tx = fb1.EMail; await DisplayAlert("Title", fb1.EMail, "OK"); } public class Feedback { public string ID { get; set; } public string EMail { get; set; } public string Subject { get; set; } public string Messege { get; set; } } WEB API: public IHttpActionResult Get_Feedback(int ID) { User user = null; try { user = db.Users.ToList().Where((u) => { return u.ID == ID; }).FirstOrDefault(); } catch (Exception r) { Debug.WriteLine(r.Message); } if (user == null) { return Ok("No record Found"); } else { var json = Newtonsoft.Json.JsonConvert.SerializeObject(user); return Json(json); } } DATABASE: USE [fdb] GO /****** Object: Table [dbo].[User] Script Date: 01/07/2018 3:06 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[User]( [ID] [int] IDENTITY(1,1) NOT NULL, [EMail] [varchar](100) NOT NULL, [Subject] [varchar](100) NOT NULL, [Messege] [varchar](200) NOT NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[User] ADD CONSTRAINT [DF_Feedback_EMail] DEFAULT ('') FOR [EMail] GO ALTER TABLE [dbo].[User] ADD CONSTRAINT [DF_Feedback_Subject] DEFAULT ('') FOR [Subject] GO ALTER TABLE [dbo].[User] ADD CONSTRAINT [DF_Feedback_Messege] DEFAULT ('') FOR [Messege] GO
Shiv Kumar YadavPosted Jun 10, 2018, 1:57 AM
Brother one question on what you have hosted your api