I have this function code made in a controller CustomEntityController
of a CustomEntity
Model from OData API
public HttpResponseMessage Post([FromBody] CustomEntity entity)
{
HttpResponseMessage response = null;
SecurityController sc = new SecurityController();
// if (sc.CheckPermission(User.Identity.Name, "CustomEntity", "Write")) {
if (sc.CheckPermission("User", "CustomEntity", "Write"))
{
_context.CustomEntity.Add(entity);
_context.SaveChanges();
StringContent stringContent = new StringContent(entity.ToString());
response = new HttpResponseMessage(HttpStatusCode.Created)
{
Content = stringContent
};
response.Headers.Add("Location", string.Format("http://{0}:{1}/CustomEntity", HttpContext.Request.Host.Host, HttpContext.Request.Host.Port));
}
return response;
}
When a client wants to create a CustomEntity
, it calls the Post
function. All works fine on the API server side, the entity is added to data base associated in _context
. But when i use the Post from a client, the client throws me an error
500 (Internal Server Error).
The response is badly formed?
This is the client code:
Container cont;
cont = new Container(new Uri("http://localhost:51342/"));
cont.Credentials = credentials;
CustomEntity lr = new CustomEntity();
lr.AreaPath = "AreaPath";
lr.Description = "Description";
lr.Frecuency = "Frecuency";
lr.Name = "Name";
lr.Reason ="Reason";
lr.RequestArea = "RequestArea";
cont.AddToCustomEntity(lr);
cont.SaveChanges(); //throws an InternalServerError