I am currently building a web.api for a pizzaria, C#, and .NET 4.6
I have a C# client that wants to select a pizza from code.. the pizza is in json.
{"id":1,"Name":"Magariatha"}
I am calling from an asp.net site hosted in iis express, I dont get through. If I call from Fiddler, the call passes through, and the pizza is selected and can get ordered ;-)
My PizzaController looks like:
public HttpResponseMessage Put(Pizza pizza)
{
string pizzaApi = "Api/Pizza/";
var handler = new WebRequestHandler() {
AllowAutoRedirect = false,
UseProxy = false };
using( var client = new HttpClient(handler)) {
client.BaseAdresse = new Uri("http://localhost:12345");
var media = new MediaTypeWithQualityHeaderValue("application/json");
client.DefaultRequestHeaders.Accept.Add(media);
// so far so good, but the trouble starts in the next line...
return client.PutAsJsonAsync(pizzaApi, pizza).
ContinueWith(x => x.Result.EnsureSuccessStatusCode)).Result;
} // end using
} // end put
It appears that something get disposed in the call to putasjson, before the server gets accessed. But I cannot figure out why.. I get the message:
Exception thrown: 'System.ObjectDisposedException' in System.Net.Http.dll