wcf - 从 wcf 服务返回 xdocument

标签 wcf linq-to-xml

我怎样才能从 wcf 服务返回 xdocument ???我需要做什么才能让 wxf 服务的方法返回一个 xdocument 对象?

最佳答案

你不能。 XDocument 不实现 IXmlSerializable。 XElement 实现 IXmlSerializable,因此您可以通过 WCF 传输它。

您还可以传输一个字符串而不是 XDocument 并在本地解析它。

前任 :

服务器 :

public string DoSomething()
{
    XDocument myXDocument = new XDocument();

    // Do stuff

    return myXDocument.ToString();
}

客户 :
XDocument doc = XDocument.Parse(myWebService.DoSomething());

关于wcf - 从 wcf 服务返回 xdocument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2406761/

相关文章:

c# - 查询 XML 以提取一条记录并将数据绑定(bind)到各个文本 block

c# - "Service X has zero application endpoints"除非我在代码中添加端点 - 为什么?

c# - 您对这种数据库工作有何看法?

wcf - 使用 WCF 的 VPN 隧道

c# - 如果命名空间也被定义为默认值,则强制 XDocument 不使用命名空间前缀

c# - 如何将 XElement 文档记录放入对象列表中

c# - WCF Rest 服务 - 获取对 HTTP 响应 header 的访问权限

c# - 两个 WCF 服务之间的共享类型

c# - 使用 C# 将 XDocument 或 XmlDocument 转换为 JSON

c# - 删除 XML 节点集合中的空/空白元素