I am starting work on some asp.net 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("http://foo")
' 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)
StreamWriter.Write(Data)
StreamWriter.Flush()
StreamWriter.Close()
RequestStream.Close()
' 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()
StreamReader.Close()
ResponseStream.Close()
' Close the WebResponse
WebResponse.Close()
End Sub
End Class