有没有办法从 DataContract 导出 XSD 架构

Is there a way to export an XSD schema from a DataContract(有没有办法从 DataContract 导出 XSD 架构)
本文介绍了有没有办法从 DataContract 导出 XSD 架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)