XML return from web service

I have an XML file that is located on the hard drive of the server my web service is running on. I need to access this file from another application.

This is my method on my web service.

Public Function getXMLFile() Dim xmlDocument As System.Xml.XmlDocument xmlDocument = New System.Xml.XmlDocument() xmlDocument.Load("C:\Sommaire.xml") Return xmlDocument End Function 

When I go to my web service and try to call my method, I get the following error:

Fix System.InvalidOperationException: An error occurred that generated the XML document. ---> System.InvalidOperationException: type System.Xml.XmlDocument cannot be used in this context.

This is caused when I try to return an xmlDocument object

From the information I gathered, it looks like SOAP, which wants to combine my XML into more XML and does not allow me to do this.

How do I retrieve an XML file from my web service if I cannot return the XML?

+4
source share
1 answer

Your function does not specify a return type, but you are trying to return an object of type System.Xml.XmlDocument.

Change

 Public Function getXMLFile() 

to

 Public Function getXMLFile() AS System.Xml.XmlDocument 

The whole fragment, as it should be:

 Public Function getXMLFile() AS System.Xml.XmlDocument Dim xmlDocument As System.Xml.XmlDocument xmlDocument = New System.Xml.XmlDocument() xmlDocument.Load("C:\Sommaire.xml") Return xmlDocument End Function 
+6
source

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


All Articles