从XSD生成DataContract [英] Generate DataContract from XSD

查看:207
本文介绍了从XSD生成DataContract的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够生成一个 DataContract 从XSD文件,preferably使用的xsd.exe工具。什么是它最简单的方法来自动生成 [DataContract] [数据成员] 在我的每个项目?

I want to be able to generate a DataContract from a XSD file, preferably using the xsd.exe tool. What is the easiest way for it to auto generate the [DataContract] and [DataMember] on each of my items?

还是有更好的方法?我试图避免在XSD文件被更改和再生每次重新创建数据契约。

Or is there a better approach? I am trying to avoid having to recreate the data contract each time the XSD file is changed and regenerated.

推荐答案

XSD.EXE 工具predates WCF,不知道任何有关 [DataContract] [数据成员] 。如果你这样做,你 XSD.EXE ,你必须切换WCF使用<一个href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"><$c$c>XmlSerializer而不是其默认<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"><$c$c>DataContractSerializer序列化数据合同。

The xsd.exe tool predates WCF and doesn't know anything about [DataContract] and [DataMember]. If you do you xsd.exe, you'll have to switch WCF to use the XmlSerializer instead of its default DataContractSerializer for serializing the data contracts.

周转基金相当于 XSD.EXE svcutil.exe的 - 它有一个参数 / dconly 只创建数据的合同,从给定XSD文件。这将生成一个C#或VB.NET文件给你,包含很好诠释了数据契约。

The WCF equivalent for xsd.exe is svcutil.exe - it has a parameter /dconly which creates the data contracts only, from a given XSD file. This will generate a C# or VB.NET file for you, containing the data contracts nicely annotated.

用法:

svcutil.exe (name of your XSD).xsd /dconly

这将产生在你的目录中的* cs文件由相同的基本名称。

This would generate a *.cs file by the same base name in your directory.

在我的经验中, svcutil.exe的是相当挑剔它的XML结构 - 所以不要感到惊讶,如果它吠叫你吨警告和/或错误的

In my experience, svcutil.exe is quite picky about its XML structures - so don't be surprised if it barks at you with tons of warnings and/or errors.

这篇关于从XSD生成DataContract的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆