Geeks With Blogs
Phil Sando

I am starting work on some vb pages to consume and work with web services.

Part 1 was to create a web form that posts xml that a dba can paste into a textbox on an aspx page. 

Here is the code;

Imports System.Net
Imports System.IO
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
        Dim Data As String
        Dim WebRequest As WebRequest
        Dim RequestStream As Stream
        Dim StreamWriter As StreamWriter
        Dim WebResponse As WebResponse
        Dim ResponseStream As Stream
        Dim StreamReader As StreamReader
        ' Create a new WebRequest which targets the web service method
        WebRequest = WebRequest.Create("
        ' Data to send 
        Data = DataToSend.Text
        ' Set the method and content type
        With WebRequest
            .Method = "POST"
            .ContentType = "text/xml"
            .Timeout = -1
            .ContentLength = Data.Length()
        End With
        ' write our data to the Stream using the StreamWriter.
        RequestStream = WebRequest.GetRequestStream()
        StreamWriter = New StreamWriter(RequestStream)
        ' Get the response from the remote server.
        WebResponse = WebRequest.GetResponse()
        ' Get the server's response status
        ResponseStream = WebResponse.GetResponseStream()
        StreamReader = New StreamReader(ResponseStream)
        ResponseLabel.Text = StreamReader.ReadToEnd()
        ' Close the WebResponse
    End Sub
End Class 


Posted on Saturday, February 27, 2010 3:22 PM | Back to top

Comments on this post: Simple web form that posts XML to a web service

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © PhilSando | Powered by: