1

I have a series of fairly complex xsd schema files and I would like to create c# classes out of them. I use xsd.exe in Visual Studio 8 and classes are generated fine. However, I would like to bypass inheritance, meaning no classes should inherit from a parent class.

I need this because I create a Web Service with these classes as parameters to my web service methods. The wsdl for the web service generates tags for these child classes. As far as I understand SAP does not accept extension tags when creating a web service client. Therefore I need a work around for this.

Any help is greatly appreciated.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
artsince
  • 1,022
  • 20
  • 36
  • I don't quite understand what you are trying to do. Let me get this - 1) You want to generate c# classes from some XSDs. 2) Then you will use the c# classes to generate a web service contract. 3) Then get some SAP component to generate a proxy from the contract? Can I ask why you start the process with the XSDs? Are you doing contract-first? – tom redfern Jun 15 '11 at 12:18
  • my web service returns an xml file based on the input parameters. I already have the xsd schema files to validate my xml. My plan is to create the same hierachical tree structure with classes and pass the this class as an argument to my web service method. – artsince Jun 15 '11 at 14:48
  • OK but since you know that your client does not support some areas of the XSD standard maybe you should use a class model which does not cause your web service contract to implement those areas. For example, do you really need to expose a class hierarchy? – tom redfern Jun 16 '11 at 09:15
  • Either that or modify the generated WSDL by hand to make your contracts consumable by your client. – tom redfern Jun 16 '11 at 09:16
  • yes, it boils down to manually manipulating the generated files... – artsince Jun 16 '11 at 09:31
  • Have you tried using xsd.exe from the command line? Visual studio does not use xsd.exe when generating code from schema so you may well get different (and better) results. – tom redfern Jun 17 '11 at 07:20

1 Answers1

1

XML Schema permits inheritence via the xs:extension element,, which allows you to modify a base complexType. When mapping this XML Schema to C# (or Java), it makes sense to map this to class inheritance.

So I guess what you want to do is rather than map to an inheritence hierarchy when an xs:extension is encountered, you want to instead copy the extended properties onto the generated class, i.e. bringing all the super-class methods into the sub-class. I very much doubt you will find an tool that will have this as an option, it is quite an obscure requirement!

Personally I would tackle this by transforming your XML Schema into the structure you want, then using your schema-to-C# tool. A suitable technology for this transformation is XSLT. However, you could write your own tool using Linq-to-XML or other XML manipulation APIs.

ColinE
  • 68,894
  • 15
  • 164
  • 232