I have a web api service that I've created as part of a separate project, and I can connect and consume the service without any problem by using HttpClient in .NET 4 and 4.5. However, HttpClient is not supported in .NET 3.5, and I need to be able to consume this service from an existing .NET 3.5 application. I've tried using WebClient, but it doesn't work. Here's my code:
WebClient client = new WebClient();
client.Headers.Add("content-type", "application/json");
string serialisedData = JsonConvert.SerializeObject(DATA);
var response = client.UploadString(URI, serialisedData);
var result = JsonConvert.DeserializeObject(response);
I've tried the solutions using WebClient offered here: Call web APIs in C# using .NET framework 3.5 and here: http://www.thepicketts.org/2012/11/how-to-access-webapi-from-a-net-3-5-client-in-c/
and this solution includes HttpClient code, event though it isn't even supported: http://forums.asp.net/t/1982540.aspx?Consume+Web+API+in+project
What am I doing wrong when trying to connect to web api using .NET 3.5?