0

I want to create a client for this public WEB API. I am new to this and I was going through this MSDN tutorial. I noticed that there are no Data Contracts defined and i cannot add service reference in my project. In the tutorial in some point it says create this class (Product) as data object that HttpClient will use.

How can i find/create this class when using the public API. In WCF i can add service reference and i will get client classes created from the service data contract. How is this done in Web Api?

1
  • I'm not sure I understand the problem: you've got a web api project which allows you to access your resources on specific urls. Product will be one of the resources which you get e.g. on the url api/product. In this case just use the HttpClient from the tutorial. Commented Apr 25, 2013 at 8:04

1 Answer 1

1

As illustrated in the MSDN article, since there's no defined contract (unlike WCF) you're gonna need to create the appropriate Types first in order to be able to consume it using REST client.

However, there are some shortcuts you can use, see here: Generate Contracts for REST objects

Also, you may find RestSharp easier to use than the official WebApi client.

Sign up to request clarification or add additional context in comments.

1 Comment

First thank you for your answer. Secondly, how should i create the types? I only have the response XML file, and i've tried to create class that matches the XML format (in terms of class name and properties names). Should I request the classes from the API host or is there another way of creating these types

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.