2

You are doing contract first development of web services in a SOA world.

After editing an XSD file, what is the best way to automatically (re)generate .net classes from the XSD files?

Bjorn Reppen
  • 22,007
  • 9
  • 64
  • 88

4 Answers4

3

xsd.exe will generate new classes for you.

Depending on how Visual Studio is set up, adding xsd.exe to "Properties / build events / post-build events" will force a regeneration every time you do a rebuild.

rbrayb
  • 46,440
  • 34
  • 114
  • 174
  • The URL for xsd.exe is: http://msdn.microsoft.com/en-us/library/x6c1kb0s(VS.71).aspx There's a bug in stackoverflow where a URL that contains () will not parse correctly using the []() construct. – rbrayb Nov 03 '08 at 21:28
  • xsd.exe is pretty weak, it cannot handle complex schema very well. The best one I used so far is http://www.codeproject.com/Articles/8433/An-XSD-to-NET-language-code-class-generator-that-a – hardywang Apr 12 '12 at 16:19
2

If using .net 1.1 or 2.0, xsd.exe. If using 3.0 or 3.5, svcutil.exe. If you don't mind using non-supported code, LINQ-to-XSD (http://blogs.msdn.com/xmlteam/archive/2008/02/21/linq-to-xsd-alpha-0-2.aspx) is cool. With any tool, be aware that some schemas do not translate well to .NET classes automatically. If you find that to be the case, code the classes by hand, and implement IXmlSerializable.

1

We are using WSCF - Web Services Contract First tool from Thinktecture to do web service development creating XSD schema first and then generating service interfaces using this tool. We've use this tool for last 2 years and I highly recommend it.

The same guys also started WSCF.blue project that is successor of their original tool and allows contract first development (read XSD first). WSCF.blue is targeted to support the Windows Communication Foundation (WCF).

Vlad N
  • 237
  • 1
  • 3
  • What to do next if I have generated classes or datasets? How can I use it in my project? – pbies Apr 27 '15 at 11:52
0

I have used http://xsd2code.codeplex.com/releases/view/22222 VS addin for this.

DSharper
  • 3,177
  • 9
  • 29
  • 47