Hello all...
I am creating a web service that pulls xml files from a website and puts the data in a dataset. At least that's what it's supposed to do. Instead, I'm only getting this:
And the beginning of the xml file I am reading looks like:
Can anyone tell from just that where it might be going awry? If you need more info, let me know.
Oh, and for those that noticed this line:
'Dim responseFromServer As String = reader.ReadToEnd()
that is for a test where I had it return a string rather than a dataset, and it worked fine, although it was embedded inside the xml that the web service generated, so there were dual <xml...> tags, like this:
but I don't think that should affect it since the first one is created by the web service itself. I could be wrong though, so I thought I'd point it out.
Any help or ideas are greatly appreciated, thanks!
Brian
I am creating a web service that pulls xml files from a website and puts the data in a dataset. At least that's what it's supposed to do. Instead, I'm only getting this:
My code from the function in the .asmx file looks like this:System.Xml.XmlException: Root element is missing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
at System.Data.DataSet.ReadXml(TextReader reader)
VB.NET:
<WebMethod()> Public Function GetDataXML() As DataSet
Dim request As Net.WebRequest = WebRequest.Create("[URL]http://brianpaulsmith.net/WF031606.xml[/URL]")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
'Dim responseFromServer As String = reader.ReadToEnd()
Dim mydata As New DataSet
mydata.ReadXml(reader)
' return the dataset
Return mydata
' Cleanup the streams and the response.
reader.Close()
dataStream.Close()
response.Close()
End Function
HTML:
<?xml version="1.0" encoding="utf-8" ?>
<data>
<item>
<timestamp>03/16/2006,00:10:00</timestamp>
.......................
</item>
</data>
Oh, and for those that noticed this line:
'Dim responseFromServer As String = reader.ReadToEnd()
that is for a test where I had it return a string rather than a dataset, and it worked fine, although it was embedded inside the xml that the web service generated, so there were dual <xml...> tags, like this:
HTML:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">
<?xml version="1.0" encoding="utf-8" ?> <data> <item> <timestamp>03/16/2006,00:10:00</timestamp>
but I don't think that should affect it since the first one is created by the web service itself. I could be wrong though, so I thought I'd point it out.
Any help or ideas are greatly appreciated, thanks!
Brian
Last edited by a moderator: