wcf 返回 XmlDocument?

发布于 2024-07-24 08:52:33 字数 368 浏览 4 评论 0原文

我有一个 WCF 服务,我在其中使用 XmlWriter 构建 XML 块。 完成后,我想让 WCF 将其作为 XmlDocument 返回。

但如果我在 [OperationContract] 中有 XmlDocument,它就不起作用:

[OperationContract]
XmlDocument GetNextLetter();

WCF 测试实用程序给出:

System.Runtime.Serialization.InvalidDataContractException:无法序列化类型“System.Xml.XmlDocument”。

I have a WCF service where Im building up a block of XML using an XmlWriter. Once complete I want to have the WCF return it as an XmlDocument.

But if I have XmlDocument in the [OperationContract] it doesnt work:

[OperationContract]
XmlDocument GetNextLetter();

The WCF test utility gives:

System.Runtime.Serialization.InvalidDataContractException: Type 'System.Xml.XmlDocument' cannot be serialized.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

智商已欠费 2024-07-31 08:52:34

将 xmlserializer 附加到您在操作合同中所做的事情上,

[OperationContract,XmlSerializerFormat]
XmlDocument GetNextLetter();

这样就可以了!

append xmlserializer on what you did in the operational contract

[OperationContract,XmlSerializerFormat]
XmlDocument GetNextLetter();

this will do it !

一个人的旅程 2024-07-31 08:52:34

如果您使用的是 .Net 3.5,那么您可以尝试返回 XElement 相反 - 这实现了 IXmlSerialized ,这是使其与 DataContractSerializer 一起使用所需的缺失成分。

If you are using .Net 3.5 then you can try returning XElement instead - this implements IXmlSerializable, which is the missing ingredient needed to make it work with DataContractSerializer.

窝囊感情。 2024-07-31 08:52:34

DataContractSerializer 可以序列化 XmlElement 实例。 因此,只需返回 XmlDocument 实例的 DocumentElement 属性即可。 请参阅:MSDN

The DataContractSerializer can serialize XmlElement instances. So just return the DocumentElement property of your XmlDocument instance. See: MSDN.

一抹微笑 2024-07-31 08:52:34

不要发送 XMLDocument,因为您可以在另一端重建它。

您可能应该发送您想要的字符串,或者构造一个可以序列化为 XML 的业务对象并传输它。

如果您有 XSD 并且想要从中创建可以序列化的业务对象,请查看带有 .net 框架的 XSD.exe 工具。

Don't send the XMLDocument, because you can reconstruct it on the other end.

You should probably send down the string that you want, or construct a business object which can be serialized to XML and transmit that.

Have a look at XSD.exe tool with the .net framework if you have an XSD and you want to make a business object from it which can be serialized.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文