5
que estoy tratando de colocar a un WebAPI método POST Asp.Net:Asp.net WebAPI HttpClient fuertemente tipado PostAync
// POST /api/citycode
public HttpResponseMessage<CityCode> Post(CityCode citycode)
{
try
{
Test.SelfTrackingEntities.BusinessLayer.BusinessManagers.CityCodeManager myCityCodeManager = new CityCodeManager(Utility.GetConnectionString());
var id = myCityCodeManager.Create(citycode);
var response = new HttpResponseMessage<Test.SelfTrackingEntities.BusinessLayer.BusinessEntities.CityCode>(citycode) { StatusCode = HttpStatusCode.Created };
response.Headers.Location = new Uri(VirtualPathUtility.AppendTrailingSlash(Request.RequestUri.ToString()) + citycode.Name);
return response;
}
catch (Exception e)
{
var response = new HttpResponseMessage(HttpStatusCode.Conflict);
response.Content = new StringContent(e.Message);
throw new HttpResponseException(response);
}
}
El Cliente Call es:
var objectContent = CreateJsonObjectContent(citycode);
objectContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
var requestMessage = new HttpRequestMessage<CityCode>(citycode, jsonMediaType);
return httpClient.PostAsync(addressSuffix, objectContent).ContinueWith(task =>
{
var responseMessage = task.Result;
return responseMessage.Content.ReadAsAsync<CityCode>().ContinueWith(readTask =>
{
return readTask.Result;
});
}).Unwrap();
Sin embargo, el servidor nunca recibe el llamada, estoy usando el JsonNetFormatter no el formateador incorporado.