How to generate a data contract class from a wcf rest service?

Topics: Web Api
Dec 30, 2010 at 12:06 PM

I want to generate a data contract class / client model from a wcf rest service. I need this so I can consume a Rest service in a typed way using httpclient in c#. I can’t use my service-side class definition as it contains implementation methods that I don’t want published to the outside world.

 So in a nutshell I want to know how to generate the Contract class from the service metadata.

            HttpClient client = new HttpClient(address);

           var contacts = client.CreateQuery<Contact>();

 I’ve seen a couple of ways of doing this, and have problems with both

 1)      Paste as xml type – can’t seem to get this installed on vs2010, win7 64x

2)      Generating a source file from the XML schema using scvUtil.exe /dconly

  • ·         I can get this working if copy the xml schema from the services help page into a file, and run scvUtil.exe /dconly against it. This is really time consuming , so far from ideal.
  • ·         Point svcutil at the assembly containing the wcf rest services, with the /dconly option. The data contracts only seem to get generated if the data contract type definition is defined in the same assembly as the service… which mine is not.
  • ·         Point svcutil at a running instance of the wcf rest service. I can’t get this working as svcutil seems to be expecting a wsdl.


Other people must have had this problem, how have you gotten around this? 


Jul 4, 2011 at 7:14 PM

No reply should we just assume that client side support is minimised from now on? The rest starter kit offerred a little help with Paste XML as a type. Has this support being discontinued? I have seen some work arounds to get it working in VS2010. Do you have any guidence on using the HTTPClient that you are offering now? I have been trying to consume a couple of rest API's and I have to say client side help is more necessary than server side help.