Generate Contracts for REST objects

earthling picture earthling · Feb 8, 2011 · Viewed 7.8k times · Source

I'm new to REST and this sounds like it should be pretty simple. In a .NET app, I can create a reference to a WCF service and the contracts for all the available types will be generated for me.

Now I'm trying to consume a REST service in a Windows Phone 7 app. While I can make my call and get back the proper response, is there a simple way to create the classes that each object would be deserialized to?

I'm using RestSharp to manage my calls. In some examples I've seen, user's have created their own classes, and generated the xml manually. I would like to avoid this if at all possible.

many thanks!

Answer

chris.w.mclean picture chris.w.mclean · Feb 9, 2011

Assuming your response is XML, you can save the xml into a file, then call xsd.exe on it to generate a schema. Call xsd.exe on the schema and it will generate a c# class file you can seriazlize and deserialize to from the xml. Here's the documeantion on how XSD.exe works:

http://msdn.microsoft.com/en-us/library/x6c1kb0s(v=VS.100).aspx