Webservice方法返回XmlDocument,参考中看到一个XmlNode [英] Webservice method return XmlDocument, Reference sees a XmlNode
问题描述
我遇到了一个我无法解决的问题,这就是为什么我求你帮助我!我正在使用WebService,并且试图从WebService方法(称为GetSystemDocument)返回XmlDocument,该方法如下:
I've faced a problem I can't solve that's why I beg you to help me! I'm working with a WebService and I'm trying to return a XmlDocument from a WebService method called GetSystemDocument which looks like :
[WebMethod(Description = "blabla")]
public XmlDocument GetSystemDocument(string DocumentName)
{
return new XmlDocument();
}
在我引用此Web服务的项目中.Visual Studio告诉我不能将类型'System.Xml.XmlNode'隐式转换为'System.Xml.XmlDocument'.
In the project where I reference this web service. Visual Studio tells me it cannot implicitily convert type 'System.Xml.XmlNode' to 'System.Xml.XmlDocument'.
如果我查看由Visual Studio生成的Reference.cs文件,则代码如下:
If I look into the Reference.cs file(generated by Visual Studio) the code looks like :
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://doc.cexp.ca/GetSystemDocument", RequestNamespace="http://doc.cexp.ca", ResponseNamespace="http://doc.cexp.ca", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Xml.XmlNode GetSystemDocument(string DocumentName) {
object[] results = this.Invoke("GetSystemDocument", new object[] {
DocumentName});
return ((System.Xml.XmlNode)(results[0]));
}
问题就在那里.代替XmlNode,我们应该看到XmlDocument,如果我手动对其进行编辑,它将生成并且一切正常.
The problem is there. Instead of XmlNode we should see XmlDocument, If I edit it manually, It builds and everything works fine.
我尝试重置IIS,更新引用,重建Web服务.有人有解决办法吗?
I've tried resetting IIS, update the reference, rebuild the web service. Someone has a solution?
这是一个相似的问题,尚未得到解答
Here is a Similar question which is unanswered.
非常感谢
推荐答案
Web方法的结果包含在作为XML文档的SOAP文档中.因此,如果要从Web方法返回XML,则应返回XmlElement.
The result of a web method is included in the SOAP document which is a XML Document. So if you want to return XML from a web method you should return an XmlElement.
[WebMethod(Descrption = "foo")]
public XmlElement GetSystemDocument(string documentName)
{
var doc = new XmlDocument();
doc.LoadXml("<foo> <bar x="a"/> </foo>");
return doc.DocumentElement;
}
更正了代码以确保它可以编译
Corrected the code to make sure that it compiles
这篇关于Webservice方法返回XmlDocument,参考中看到一个XmlNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!