2012-03-20 123 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