从Web服务返回XML

问题描述 投票:4回答:1

我有一个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文件?

c# .net xml vb.net web-services
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.