为什么 DataContractSerializer 不支持属性? [英] Why are attributes not supported with the DataContractSerializer?

查看:53
本文介绍了为什么 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?

推荐答案

DataContractSerializer 在创建时考虑到了代码优先"的理念 - 它可以很好地映射到大多数编程语言(记录、列表),并且它不处理出于性能原因的所有 XML 构造(例如属性或乱序元素).

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) 仍然支持使用 XmlSerializer,它可以处理 AFAIK 的所有 XML 构造.如果 DataContractSerializer 不能处理它,svcutil 应该使用 XmlSerializer 创建一个契约.

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.

这篇关于为什么 DataContractSerializer 不支持属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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