Click here to Skip to main content
16,015,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hope you guys can help me in this one.

I am trying to create a web service using that will return and display an xml document that has been populated using an SQL query.

Below is my current code.

VB
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Xml
Imports System.Data
Imports System
Imports System.Collections.Generic
Imports System.Linq

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <system.web.script.services.scriptservice()> _
<webservice(namespace:> _
<webservicebinding(conformsto:> _
<global.microsoft.visualbasic.compilerservices.designergenerated()> _
Public Class RetrieveJobs
     Inherits System.Web.Services.WebService

    <webmethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

    <webmethod()> _
    Public Function GetUserInfo() As XmlDocument
        Dim xml As String = ""
        Dim xmlDoc As New XmlDocument()

        Try
            Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("PeopleConnectionString").ConnectionString)
                con.Open()
                Dim query As String = "SELECT * FROM sysdba.USERINFO FOR XML RAW ('USERINFO'), ROOT ('USERINFO'), ELEMENTS"

                Dim cmd As New SqlCommand(query, con)

                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.Read() Then
                    xml = dr(0).ToString()
                End If
                con.Close()
            End Using
        Catch generatedExceptionName As Exception
        End Try

        xmlDoc.LoadXml(xml)

        Return xmlDoc

    End Function

End Class


This code is heavily based on the following post - http://www.ashishblog.com/blog/how-to-create-and-return-xml-document-from-a-web-service-c-net/[^]

The problem I have is that an error is thrown up when testing it in Visual Studio 2010 stating 'Unexpected end of file while parsing Name has occurred. Line 1, position 2034.'

Does anyone know what it means?
Is this a suitable way of creating an XML file from an SQL query?

Any help would be appreciated.
Cheers
Posted
Comments
Sergey Alexandrovich Kryukov 19-Oct-11 13:31pm    
Did you check up that an XML is well-formed?
--SA
Night_Devil 19-Oct-11 14:04pm    
How would I go about checking that?

1 solution

When you consume the web service, you may not have a large enough buffer for the information.
For example, in the app.config for the consumer, you may have a property like maxStringContentLength variable. I think it defaults to 8192, try making it bigger, perhaps.
 
Share this answer
 
Comments
Night_Devil 26-Oct-11 11:17am    
Sorry for the late reply. I think you are right about me not having a large enough buffer as queries which retrieve smaller amounts of data work fine.

I am unable to find anything like maxStringContentLength or a <system.servicemodel> section. I know where it should go but not what to populate it with. Any pointers?

This web service I am making is for a phone app. So would the 'consumer' be the phone app or would I still need to change something on my side.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900