VS2010将System.Xml.XmlElement与System.Xml.Linq.XElement混淆了吗? [英] VS2010 confuses System.Xml.XmlElement with System.Xml.Linq.XElement?

查看:146
本文介绍了VS2010将System.Xml.XmlElement与System.Xml.Linq.XElement混淆了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一种方法创建了WCF服务,该方法返回 System.Xml.XmlElement

I have created a WCF service with one method which returns a System.Xml.XmlElement:

接口:

[ServiceContract]
public interface IWCFService
{
    [OperationContract]
    XmlElement Execute(...);
}

服务:

public XmlElement Execute(...)
{
    XmlNode node = ...;

    return (XmlElement)node;
}

当我尝试访问服务器上部署的服务时

When I try to access the service deployed on my server

WCFServiceClient service = new WCFServiceClient("WSHttpBinding_IWCFService");
XmlElement node = service.Execute(...);

我收到错误:


不能将类型'System.Xml.Linq.XElement'隐式转换为'System.Xml.XmlElement'

Cannot implicitly convert type 'System.Xml.Linq.XElement' to 'System.Xml.XmlElement'

在搜索服务解决方案时,找不到对 System.Xml.Linq.XElement 的任何引用。期待 System.Xml.XmlElement 是我的错吗?还是VS 2010在跟我鬼混?

Searching my service solution, I cannot see any reference to System.Xml.Linq.XElement. Is it wrong of me to expect a System.Xml.XmlElement or is VS 2010 fooling around with me?

推荐答案

对我来说,最有效和最简单的方法是右键单击服务参考,然后单击配置服务参考。在底部的对话框中,您将看到2个单选按钮,分别显示在所有引用的程序集中重用类型或在指定的引用的程序集中重用类型。单击指定程序集的第二个选项。然后将启用该列表框,您可以检查所有程序集,并保留 System.Xml.Linq 未选中。这样,每次更新服务引用时,您将获得预期的结果,并将其存储在客户端的配置中。

What I have found works the best and easiest for me is to right-click on the service reference and then click on "Configure Service Reference". Once in the dialog box for this at the bottom you will see 2 radio buttons that say "Reuse types in all referenced assemblies" or "Reuse types in specified referenced assemblies". Click on the 2nd option for 'specified assemblies'. The listbox will then be enabled and you can check all assemblies and leave System.Xml.Linq unchecked. This way every time you update the service reference you will get the expected results and this will be stored in the configuration of the client.

这篇关于VS2010将System.Xml.XmlElement与System.Xml.Linq.XElement混淆了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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