The Webservice method returns an XmlDocument, the link sees an XmlNode

I ran into a problem, I can’t decide why I ask you to help me! I am working with a WebService, and I am trying to return an XmlDocument from a WebService method called GetSystemDocument, which looks like this:

[WebMethod(Description = "blabla")] public XmlDocument GetSystemDocument(string DocumentName) { return new XmlDocument(); } 

In a project where I refer to this web service. Visual Studio tells me that it cannot implicitly convert the type "System.Xml.XmlNode" to "System.Xml.XmlDocument".

If I look into the Reference.cs file (generated by Visual Studio), the code looks like this:

 /// <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])); } 

There is a problem. Instead of XmlNode, we should see XmlDocument, if I edit it manually, it builds and everything works fine.

I tried resetting IIS, updating the link, rebuilding the web service. Does anyone have a solution?

Here is a similar question that does not answer.

thanks a lot

+4
source share
1 answer

The result of the web method is included in the SOAP document, which is an XML document. Therefore, if you want to return XML from a web method, you must 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; } 

Edit: Fixed code to make sure it compiles

+4
source

Source: https://habr.com/ru/post/1346803/


All Articles