How to create Data Contract from XML Schema

Topics: July and December Releases Forum
Jan 30, 2007 at 3:31 AM
When right-clicking on a WCF DataContracts project, there is choice to Create XML Serializable Type from Schemas but there isn't a Create Data Contract from Schema menu option. When unlocking the solution there isn't a way to enable this either.

Any suggestions on how to do this or exact syntax with SvcUtil.exe utility to create DataContract .cs file?
Jan 30, 2007 at 7:12 AM
You are correct, generating a DataContract from an XSD isn't supported in this release of WCF Service Factory. You can use svcutil for that with the folowing syntax: svcutil /dconly *.xsd

of course you can specify your .xsd file and also supply a name for the generated DataContract file. You can find all options and arguments for svcUtil.exe at

Jan 30, 2007 at 7:33 PM
Another alternative is to include those XSDs in a WSDL file and run the "Create Service Contract from WSDL" recipe. As long as the XSD "can" generate a DataContract, it will. You'll just have to delete the resulting interface file.

It would be great if a community member would just build a recipe that does it :) you know I'd be happy to post it here for everyone else to use giving credit appropriately ;)

Feb 6, 2007 at 7:21 PM
I have decided to use xsd.exe instead of svcutil to generate the types. The main reason is that svcutil /dconly does not support 'unbounded' elements so I cannot return an array of types in my generated classes, e.g. an Order contains '0 or more' OrderDetails.

I guess this is done for maximum portability for service clients but only allows use of trivial XML schemas. My assumption is that most Java implementations know how to consume an array of types, so don't know why this could have been supported in SvcUtil.