Reputation: 87
I am attempting to call a Web API POST action (.Net Core) from a WinForms app (.Net Framework 4.7) via Flurl. However, when I try to debug the exception Flurl throws, my request doesn't even enter the controller itself.
Trying to debug the problem line by line didn't help. I suppose because since Web API and WinForms are two different projects in the same solution, I can't enter the debugging from the form to controller?
at Flurl.Http.FlurlRequest.<HandleExceptionAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Flurl.Http.HttpResponseMessageExtensions.<ReceiveJson>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BTM.WinUI.APIService.<Insert>d__12`1.MoveNext() in C:\Users\User\Documents\Visual Studio 2019\Projects\APITest\APITest.WinUI\APIService.cs:line 61
Basically I instantiate an object of a class I made and call my API service:
var entity = new UserRegistrationModel
{
Username = "test",
Email = "[email protected]",
Password = "test",
PasswordConfirmation = "test",
Roles = new List<int>()
};
entity.Roles.Add(1);
entity.Roles.Add(2);
await _service.Insert<User>(entity);
This is what my call looks like:
public async Task<T> Insert<T>(object request)
{
string url = "https://localhost:44365/api/users";
return await url.PostJsonAsync(request).ReceiveJson<T>();
}
My controller should handle it by adding a new user to the database and returning an User
object, but the method's code gets never executed.
[HttpPost]
public User Post(UserRegistrationModel request)
{
return _service.Register(request);
}
Upvotes: 1
Views: 1127
Reputation: 3005
It could be that Flurl is unable to send a POST request to your localhost due to HTTPS
. Try disabling SSL in your ASP NET Core Web API project.
Upvotes: 2