为什么 DataContractSerializer 不支持属性?
我根据客户的文档创建 xsd,并且所有 xsd 都有属性。我一直在使用 xsd.exe 从 xsd 生成类,但我读到 DataContractSerializer 不支持属性。为什么不呢?这是否意味着我只能有一个只有元素的soap+xml 文件?这是不可能的,因为我不创建请求。有没有办法指定 svcutil 来识别属性?
I create xsd's based upon client's documentation and all of the xsd's have attributes. I have been using xsd.exe to generate the classes from the xsd's, but I read that attributes aren't supported for the DataContractSerializer. Why not? Does this mean that I can only have an soap+xml file with just elements? This is not possible because I don't create the requests. Is there a way to specify to svcutil to recognize attributes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataContractSerializer 的创建秉承了“代码优先”的理念 - 它可以很好地映射到大多数编程语言(记录、列表),并且它不处理所有 XML 构造(例如属性或无序元素、例如)出于性能原因。
WCF (svcutil) 仍然支持使用 XmlSerializer,它可以处理 AFAIK 的所有 XML 构造。如果 DataContractSerializer 无法处理,svcutil 应使用 XmlSerializer 创建协定。
DataContractSerializer was created with a "code-first" philosophy in mind - it maps well to most programming languages (records, lists), and it doesn't handle all of XML constructs (such as attributes, or out-of-order elements, for example) for performance reasons.
WCF (svcutil) still supports using the XmlSerializer, which can handle AFAIK all of the XML constructs. svcutil should create a contract using the XmlSerializer if the DataContractSerializer can't handle it.