简体   繁体   中英

Returning XML from a Web Service

I have an XML file that sits on the hard drive of a Server running my Web Service. I need to access that 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 navigate to my Web Service and try to invoke my method, I get the following error:

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Xml.XmlDocument may not be used in this context.

This is caused when I try to return the xmlDocument object

From the information I gathered, it's like SOAP wants to wrap my XML in more XML and stops me from doing that.

How do I go about getting the XML File from my Web Service if I can't return XML?

Your function doesn't specify a return type, yet you're trying to return an object of type System.Xml.XmlDocument.

Change

Public Function getXMLFile() 

to

Public Function getXMLFile() AS System.Xml.XmlDocument

Entire snippet 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM