Why are attributes not supported with the DataContractSerializer?

爷,独闯天下 提交于 2020-01-03 21:09:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6074708/why-are-attributes-not-supported-with-the-datacontractserializer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!