0

Hi I'm a very big begginer to VB and I cannot figure out how to return the result from the XML writer back to the client. I've used the string writer to create the format but I don't know how to RETURN it in a format that doesn't give an error.

Dim str_returnstring As New StringBuilder()
Using string_writer As New StringWriter(str_returnstring)
    Using writer = XmlWriter.Create(string_writer)
        writer.WriteStartDocument(True)
        writer.WriteStartElement("playlists")
        Dim var_arrayposition = 0
        For Each arr_playlistid In arr_playlistids
            writer.WriteStartElement("playlist")
            writer.WriteStartElement("playlistid")
            Dim int2string = Convert.ToString(arr_playlistid)
            writer.WriteString(int2string)
            writer.WriteEndElement()
            writer.WriteStartElement("playlistame")
            writer.WriteString(arr_playlistnames(var_arrayposition))
            writer.WriteEndElement()
            var_arrayposition += 1

            writer.WriteEndElement()
        Next
        writer.WriteEndElement()
        writer.WriteEndDocument()
    End Using

End Using
1
  • can you please include the full function and clarify how you're setting up the web service? Commented Nov 26, 2015 at 0:15

1 Answer 1

1

If this is a .NET Web Service then returning your XML as a response from one of the WebMethod functions should be as simple as:

<WebMethod()>
Public Function GetXML() As String
    'Your XML Generating Code Here
    Return str_returnstr.ToString()
End Function

Basically, inside your web service you declare a number of methods with the <WebMethod()> attribute attached. Those are the methods your web service exposes to requestors. To return data in a response to a call to one of these methods, just Return the way you normally would from a method call, and the background code will take care of the rest for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.