My program is for Self hosting a Web API in a Windows Application. As I dont have much experience in web servie, I request someone's help to fix the problem.
I could make a console application successfully. But when I change it in to Windows application, my IDE goes stuck with Error "The application is in Break Mode".
Console Program;
using System.Web.Http;
using System.Web.Http.SelfHost;
Main Function:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}", new { id = RouteParameter.Optional });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit."); // Removed in Win Form
Console.ReadLine(); // Removed in Win Form
}
API Controller Class; I need to receive data here from "FromBody" attribute.
public class FieldsController : ApiController
{
[HttpPost]
public void PostAction([FromBody] Field model)
{
int patientID;
string name;
string age;
patientID = model.patientID;
name = model.patientName;
age = model.patientAge;
}
}