TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Peter
NA
14
26.1k
Web Api get complex type
Jan 23 2014 6:21 AM
Hi
I have written a small ApiController service in C#, which has a "get" method:
[AcceptVerbs("GET")]
public Product GetProduct(Guid id)
If I call this directly in a browser, eg "http://myserver/api/v1/GetProduct/9cfbf113-30a2-4189-b4a8-53fdecca1f81", then I see a result like I'd expect.
But how do I call this endpoint from a c# application? I get an error like: "no MediaTypeFormatter is available to read an object of type Product from content with media type 'text/javascript'".
My code:
var client2 = new HttpClient();
client2.BaseAddress = new Uri("http://myserver");
var resp2 = client2.GetAsync("api/v1/GetProduct/9cfbf113-30a2-4189-b4a8-53fdecca1f81").Result;
Product responsePD2 = null;
if (resp2.IsSuccessStatusCode)
{
responsePD2 = resp2.Content.ReadAsAsync<Product>().Result;
}
else
{
}
How do I convert the returned result to a Product type?
Thanks.
Reply
Answers (
1
)
Bridging between synchronous and asynchronous calls
the request failed with http status 417 expectation failed