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?

mravko
  • 49
  • 1
  • 6
  • 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. – Joanna Derks Apr 25 '13 at 08:04

1 Answers1

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.

Community
  • 1
  • 1
haim770
  • 48,394
  • 7
  • 105
  • 133
  • 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 – mravko Apr 25 '13 at 11:07