Alexandre
Alexandre

Reputation: 4602

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?

Upvotes: 4

Views: 8728

Answers (1)

David
David

Reputation: 73554

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

Upvotes: 6

Related Questions