Vruca-Delun
New Member
I have a web method like the following\[code\] public HttpResponseMessage PostDeviceControl(DeviceAccessRequest deviceAccessRequest) { var deviceAccessResponse = new DeviceAccessResponse(deviceAccessRequest.RequestId) { Status = "OK" }; var response = Request.CreateResponse<DeviceAccessResponse>(HttpStatusCode.OK, deviceAccessResponse); return response; }\[/code\]This is how I'm consuming it from a C# application, and it works great\[code\] using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:55208/"); var request = new DeviceAccessRequest { RequestId = Guid.NewGuid().ToString(), DeviceId = "ACU/B2/01/R1", AccessType ="Unlock", LoginId = "tester", Password = "tester" , }; var response = client.PostAsJsonAsync("api/accesspanel", request).Result; if (response.IsSuccessStatusCode) { var deviceAccessResponse = response.Content.ReadAsAsync<DeviceAccessResponse>().Result; } }\[/code\]This is my jquery snippet\[code\]var request = { RequestId: "123", DeviceId: "ACU/B2/01/R1", AccessType: "Unlock", LoginId: "tester", Password: "tester"};alert(JSON.stringify(request));$.ajax({ url: 'http://localhost:55208/api/accesspanel', type: 'POST', data: JSON.stringify(request), contentType: "application/json;charset=utf-8", success: function (data) { alert(JSON.stringify(data)); }, error: function (x, y, z) { alert(x + '\n' + y + '\n' + z); }});\[/code\]I have set a breakpoint in my web api method, but it doesn't break. and the error portion of my ajax() gets called.What am I doing wrong?