我用一个返回System.Xml.XmlElement的方法创建了一个WCF服务
接口:
[ServiceContract]
public interface IWCFService
{
[OperationContract]
XmlElement Execute(...);
}服务:
public XmlElement Execute(...)
{
XmlNode node = ...;
return (XmlElement)node;
}当我试图访问部署在服务器上的服务时
WCFServiceClient service = new WCFServiceClient("WSHttpBinding_IWCFService");
XmlElement node = service.Execute(...);我知道错误:
不能隐式地将“System.Xml.Linq.XElement”转换为“System.Xml.XmlElement”
在搜索我的服务解决方案时,我看不到对System.Xml.Linq.XElement的任何引用。我期望得到一个System.Xml.XmlElement是错的,还是VS 2010在和我鬼混?
发布于 2010-12-17 06:45:19
1)从客户端删除system.xml.linq引用2)更新服务引用3)重新生成的Reference.cs文件现在将引用XmlElement而不是XElement
发布于 2010-05-19 08:19:20
我不想回答我自己的问题,但这里说的是:
据我所见,System.Xml.XmlElement可以用作WCF服务的返回类型。默认情况下,在WCF中使用的DataContractSerializer可以支持这种类型,因此不需要使用XmlSerializer。
然而,我的问题与序列化无关,但多亏了Raj 提出了这种可能性。
我遵循了微软提供的WCF教程,它告诉您在要使用该服务时,要将WCF服务添加为服务引用。在VS2008中,这似乎是可以的,但是当切换到VS2010时,这种方法更改返回类型从System.Xml.XmlElement切换到(更新的System.Xml.Linq.XElement )。要解决这个问题,您需要将服务添加为Web引用。
https://stackoverflow.com/questions/2855597
复制相似问题