ReadAsDataContract - still available?

Topics: Web Api
Jan 23, 2011 at 11:19 AM

Hi there,

 

Does the method, ReadAsDataContract available? It was in the starter kit.

 

This was a great way to get the data returned from your rest back into a standard c# class.

 

Where is it located, in what namespace?

 

Thanks

Coordinator
Jan 23, 2011 at 8:12 PM

Yes. That extension method and a bunch of new ones including supporting custom formats are available in the Microsoft.Net.Extensions project. There are unit tests as well which show how the extensions work.

The samples don't currently use this yet, but we are looking to update them / add new samples, that and add some documentation to our wiki.

Jan 24, 2011 at 11:00 AM

Thanks Glenn, great news.

 

Sep 20, 2011 at 11:39 PM

I just downloaded 0.50 version of the HttpClient. I cannot still find the dll which has the ReadAsDataContract.. I looked other packages with WebAPI , cannot seem to find Microsoft.Net.Extensions or Microsoft.Http.Extensions.

Can you guys look into this. where are these ReadAsDataContract and ReadAsObject extension methods?

Regards

Emre

Coordinator
Sep 21, 2011 at 12:05 AM

You won't find that method in Preview 5. Instead you will enable DataContract support by setting the UseDataContractSerializer property on the XmlMediaTypeFormatter. If you new up a formattter collection, it exposes a property currently for the formatter. You will then use the ReadAs method and pass in that formatter collection.

Glenn