問題描述
我正在使用 DataContractSerializer 將我的類序列化/反序列化到 XML.一切正常,但在某些時候,我想為這些 XML 文件的格式建立一個獨立于實際代碼的標準模式.這樣,如果序列化過程中出現問題,我總是可以返回并檢查標準模式應該是什么.或者,如果我確實需要修改架構,那么修改是一個明確的決定,而不僅僅是修改我的代碼的后續影響.
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 format of these XML files independent of the actual code. That way if something breaks in the serialization process I can always go back and check what the standard schema should be. Or if I do need to modify the schema the modification is an explicit decision rather then just a later affect of modifying my code.
此外,其他人可能正在編寫其他可能不是基于 .NET 的軟件,這些軟件需要從這些 XML 文件中讀取.我希望能夠為他們提供某種架構文檔.
In addition, other people may be writing other software that may not be .NET based that would need to read from these XML files. I'd like to be able to provide them with some kind of documentation of the schema.
DataContract 和 XSD 架構之間是否存在某種關系.有沒有辦法將類中的 DataContract 屬性導出為 XSD 架構?
Is there some relationship between a DataContract and an XSD schema. Is there a way to export the DataContract attributes in classes as an XSD schema?
推薦答案
Svcutil.exe 可以導出已編譯數據合約的元數據".
DataContract 和 XSD 之間存在關系:
當使用元數據終結點或 ServiceModel 元數據實用工具 (Svcutil.exe) 從 Windows Communication Foundation (WCF) 服務導出元數據時,DataContractSerializer 會將 CLR 類型映射到 XSD.有關詳細信息,請參閱數據協定序列化程序.
The DataContractSerializer maps CLR types to XSD when metadata is exported from a Windows Communication Foundation (WCF) service using a metadata endpoint or the ServiceModel Metadata Utility Tool (Svcutil.exe). For more information, see Data Contract Serializer.
當使用 Svcutil.exe 訪問 Web 服務描述語言 (WSDL) 或 XSD 文檔并為服務或客戶端生成數據協定時,DataContractSerializer 還將 XSD 映射到 CLR 類型.
The DataContractSerializer also maps XSD to CLR types when Svcutil.exe is used to access Web Services Description Language (WSDL) or XSD documents and generate data contracts for services or clients.
即使在瀏覽器中,您也可以通過 設置 MEX 端點.
默認情況下,WSDL 將包含對可以通過端點訪問的 XSD 的引用.
You can get the XSD(s) at run-time as well, even in your browser, by setting up a MEX endpoint.
The WSDL by default will contain references to XSD(s) that can be accessed through the endpoint as well.
這篇關于有沒有辦法從 DataContract 導出 XSD 架構的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!