views:

1259

answers:

2

I want to be able to Generate WCF C# DataContract from XSD file, preferably using the xsd.exe tool. What is the easiest way for it to auto generate the

[DataContract] and [DataMember] on each of my items?

Or is there a better approach? I am trying to avoid having to recreate the Data Contract each time the XSD file is changed and regenerated.

p.s I am new to both WCF and XSD

+4  A: 

The xsd.exe tool predates WCF and doesn't know anything about [DataContract] and [DataMember]. If you do you xsd.exe, you'll have to switch WCF to use the XmlSerializer instead of its default DataContractSerializer for serializing the data contracts.

The WCF equivalent for xsd.exe is svcutil.exe - it has a parameter /dconly which creates the Data Contracts only, from a given XSD file. This will generate a C# or VB.NET file for you, containing the data contracts nicely annotated.

Usage:

svcutil.exe (name of your XSD).xsd /dconly

This would generate a *.cs file by the same base name in your directory.

In my experience, svcutil.exe is quite picky about its XML structures - so don't be surprised if it barks at you with tons of warnings and/or errors.

marc_s
Thank you I did not know this tool existed
Daveo
A: 

wcfBlue

http://wscfblue.codeplex.com/

oren