我有一个XML文件,它位于运行我的Web服务的服务器的硬盘上。我需要从另一个应用程序访问该文件。
这是我的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:生成XML文档时出错。 ---> System.InvalidOperationException:在此上下文中不能使用System.Xml.XmlDocument类型。
这是在我尝试返回xmlDocument
对象时引起的
从我收集的信息来看,就像SOAP希望将XML包装在更多XML中并阻止我这样做。
如果我无法返回XML,如何从Web服务获取XML文件?
您的函数未指定返回类型,但您尝试返回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