This project is read-only.

Can I generate datacontract-code from XSD AND existing assembly?

Jul 13, 2010 at 7:03 PM
Assume I have the following projects in my solution: 1. Company.Services.DataContracts 2. Company.Services.CasefolderService.DataContracts - In project1 I have written som classes and marked them with DataContract-attributes. - I then used svcutil.exe /t:metadata /dcOnly bin\Debug\Company.Services.DataContracts.dll to generate .XSD from the datacontracts. - In project2 I started out with schemas from another company. The main schema defines a "casefolder" wich I want to "inherit". Unfortunately these schemas don't support DataContractSerializer :( - I created a new schema called companyCasefolder.xsd. Her I have a element CompanyCaseFolder wich is an xs:extension base="3rdPart:casefolder. - My CompanyCasefolder contains some of the DataContracts from Company.Services.DataContracts. In my new schema I'm using <xs:import namespace="http://company/services/datacontracts/user/2010/07" schemaLocation="../Company.Services.DataContracts/"/> - Now I can generate code by rightcliking all the schemas->>generate datacontract code. The "problem" is that it doesn't reuse the types from project1, but instead regenerates them. Also the CLR-namespace in the generated code is now Company.Services.CasefolderService.DataContracts for the types I defined in Company.Services.DataContracts. If I use svcutil to generate code, I'm able to map namespaces with /namespace:http://company/services/datacontracts/user/2010/07,Company.Services.DataContracts and reference assembly with /reference:..\Company.Services.DataContracts\bin\Debug\Company.Services.DataContracts.dll. Now the Namespaces are "correct", but it still regenerates all the types from project1.. I'm guessing that svcutil.exe fails to just reference the types from project1 since they are DataContracts, and the other generated types use XmlSerializer? Is it possible to use both XmlSerializer and DataContractSerializer? I'm not sure if my "problem" is even a real problem, since datacontract are just supposed to be containers, and the xml-namespace still matches.. Maybe I should just leave the code as it is? Do you have any advice for me? :)