Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

c# - VS2010 confuses System.Xml.XmlElement with System.Xml.Linq.XElement?

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

Interface:

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

Service:

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(...);

I get the error:

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...