2012-03-20 119 views
4

我有一個XML文件位於運行我的Web服務的服務器的硬盤驅動器上。我需要從另一個應用程序訪問該文件。從Web服務返回XML

這是我在我的Web服務

Public Function getXMLFile() 
    Dim xmlDocument As System.Xml.XmlDocument 

    xmlDocument = New System.Xml.XmlDocument() 
    xmlDocument.Load("C:\Sommaire.xml") 

    Return xmlDocument 
End Function 

方法,當我瀏覽到我的Web服務,並嘗試調用我的方法,我得到以下錯誤:

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

這是當引起我嘗試返回xmlDocument對象

從我收集的信息中,就像SOAP想要將我的XML封裝在更多的XML中並阻止我這樣做。

如果我無法返回XML,我該如何從我的Web服務獲取XML文件?

回答

6

你的函數沒有指定返回類型,但你試圖返回一個System.Xml.XmlDocument類型的對象。

變化

Public Function getXMLFile() 

Public Function getXMLFile() AS System.Xml.XmlDocument 

整個片段,因爲它應該是:

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 
+1

哦,做VB的喜悅!非常感謝!它的工作:) – Alexandre 2012-03-20 18:48:27

+0

很高興幫助! – David 2012-03-20 18:49:02

+3

@PeekaySwitch:你應該把'OPTION STRICT ON'變成你的,並且你不會有這樣的問題。 – 2012-03-20 18:55:13