How do I use XML Schema Definition Tool (Xsd.exe)

3.3k Views Asked by At

Seriously I'm confused. I have an .XSD that is made from a class so that I can pass to a webservice. It got it over to the webservice as an XMLSchema object and now I need to make it into a class so that I can make objects out of it on the webservice side. I know that XSD.exe is the answer but I'll be darned if I can puzzle out exactly how to implement this thing. I need it to do this conversion at run time so I need to put the code for it into my project and all the references I've seen to using XSD.exe talk about calling it from the command line. My .XSD is below.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Field">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Name" type="xs:string" />
        <xs:element name="Type" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

In my project this is living in an XMLSchema object. How do I turn it into a class?

-Thank You so much for any help you can give.

2

There are 2 best solutions below

4
On BEST ANSWER

If you're doing webservices in .NET, you do not need to resort to fiddling with XSD.

There is a wsdl.exe tool if you use the 1st gen webservices stack from .NET, aka .ASMX webservices. There is the svcutil.exe tool that you would use if you are relying on WCF.

Those things generate client-side proxy code, which provide classes that allow webservices clients to invoke web services. Implicitly they rely on XSD, but you do not need to use the xsd.exe tool directly, nor do you need to deal directly with .xsd files.

0
On

If you are using .NET 2.0, then simply use "Add Web Reference" and point to the WSDL file of the service. If you are using any later version, then use "Add Service Reference".

Both of these will create the classes you need to communicate with the service, and no need to play with XSD.EXE or even WSDL.EXE.