This project is read-only.

HttpClient in Preview 5

Topics: Web Api
Sep 27, 2011 at 8:38 AM


What are breaking changes for HttpClient in preview 5?

Earlier, HttpClient used to take URI as a parameter in it's constructor.

var client = new HttpClient(new Uri(uri));

But now, I am getting error "The best overloaded method match for 'System.Net.Http.HttpClient.HttpClient(System.Net.Http.HttpMessageHandler)' has some invalid arguments".

It seems now HttpClient accepts only HttpMessageHandler in it's constructor.

Similarly, it's "Channel" property seems to have disappeared.
client.Channel = new TracingResponseChannel(this.TraceResponse);

I am getting error "'System.Net.Http.HttpClient' does not contain a definition for 'Channel' and no extension method 'Channel' accepting a first argument of type 'System.Net.Http.HttpClient' could be found (are you missing a using directive or an assembly reference?)"

This used to work in the past!



Sep 27, 2011 at 9:02 AM

List of breaking changes are here though they don't include everything.

Channels => Handlers in Preview 5. All you need to do is substitute Handler in the type name and you will find it, i.e. DelegatingChannel => DelegatingHandler, HttpClientChannel => HttpClientHandler, etc.

In terms of the constructor of HttpClient yes that was changed to not allow passing in a Uri as the feedback we got was that it was not clear how that Uri composed with the Uri you can pass when you call methods like Post, Get, etc. With the new changes, you will pass in your uri when you send the message.