Is there a way to export an XSD schema from a DataContract

后端 未结 3 726
清酒与你
清酒与你 2021-01-02 08:32

I\'m using DataContractSerializer to serialize/deserialize my classes to/from XML. Everything works fine, but at some point I\'d like to establish a standard schema for the

3条回答
  •  难免孤独
    2021-01-02 08:46

    You might be able to generate schema files from DataContracts using the svcutil.exe tool that comes with Visual Studio.

    svcutil myAssembly.dll
       - Generate metadata documents for Service Contracts and associated types in an assembly
    
    svcutil myServiceHost.exe /serviceName:myServiceName
       - Generate metadata documents for a service, and all associated Service Contracts and data types in an assembly
    
    svcutil myServiceHost.exe /dconly
       - Generate metadata documents for data types in an assembly
    

    I believe I messed with this at one point in the past, and may or may not have gotten it to work. Another easy way to generate schemas is to stand up a WCF service that uses your data contracts, and access the WSDL. The WSDL will import all the xsds for the DataContracts.

提交回复
热议问题