views:

965

answers:

3

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?

+2  A: 

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.

nzpcmad
The URL for xsd.exe is:http://msdn.microsoft.com/en-us/library/x6c1kb0s(VS.71).aspxThere's a bug in stackoverflow where a URL that contains () will not parse correctly using the []() construct.
nzpcmad
+1  A: 

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  A: 

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