"HTTP GET" Wont display - PLEASE HELP !

realmscape

New member
Joined
Mar 19, 2005
Messages
1
Programming Experience
Beginner
I'm new to VB .NET and I'm trying to home some skills on calling Web Service methods from a VB .NET console application VIA HTTP GET, HTTP POST & SOAP. The HTTP POST works with no problem. However, the HTTP GET and SOAP messages don't give me the desired result if any at all. The HTTP GET only writes the Console.WriteLine("------------HTTP POST--------------") line and nothing else. It also gives me the following error:

'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.

'Tester': Loaded 'C:\Documents and Settings\Sunny Bear\My Documents\Visual Studio Projects\Tester\bin\Tester.exe', Symbols loaded.

'Tester.exe': Loaded 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded.

'Tester.exe': Loaded 'c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded.

The program '[2992] Tester.exe' has exited with code 0 (0x0).

The SOAP message only writes the

"Console.WriteLine("------------SOAP--------------")" line and breaks on the line of code that states "If content.Length > 0 Then" ..... It also gives the following error in the output window:

'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.

'Tester': Loaded 'C:\Documents and Settings\Sunny Bear\My Documents\Visual Studio Projects\Tester\bin\Tester.exe', Symbols loaded.

'Tester.exe': Loaded 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded.

'Tester.exe': Loaded 'c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded.

An unhandled exception of type 'System.NullReferenceException' occurred in Tester.exe

Additional information: Object reference not set to an instance of an object.

'Tester.exe': Loaded 'c:\windows\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll', No symbols loaded.

I'd appreciate really appreciate any help anyone has. I've been stuck for about 3 days on this one. Here is my Console application code.....

Thannnnxxxx, Realmscape.....You can also reply to realmscape@yahoo.com


Imports
System.Net

Imports System.IO

Imports System.Text

Imports System.Xml

Imports System.Collections.Specialized

Imports System.Diagnostics



Module Tester

Sub Main()

'Add to Main to enable tracing to the Console

Trace.Listeners.Add(New TextWriterTraceListener(Console.Out))

Trace.AutoFlush =
True



''***** GET *****'

'Uses the GET METHOD to retrieve information from the Web Service

Console.WriteLine("------------HTTP Get--------------")

Dim urlGet AsString = "http://localhost/Woodgrove/Bank.asmx/GetAccount?intvendor=1"

GetData(urlGet, "", "GET", "")

'***** POST *****'

'Uses the POST METHOD to retrieve information from the Web Service

Console.WriteLine("------------HTTP POST--------------")

Dim urlPost AsString = "http://localhost/Woodgrove/Bank.asmx/GetAccount"

GetData(urlPost, "application/x-www-form-urlencoded", "POST", "intvendor=1")

'urlstring 'content-type 'method 'variable

'***** SOAP *****'

'Uses the SOAP to retrieve information from the Web Service

Console.WriteLine("------------SOAP--------------")

Dim urlSOAP AsString = "http://localhost/Woodgrove/Bank.asmx"

Dim strSoap AsString = BuildSOAPMessage()

Dim strAction AsString = "SOAPAction: ""http://tempuri.org/GetAccount"""

GetData(urlSOAP, "text/xml; charset=utf-8", "POST", strSoap, strAction)

Console.ReadLine()

EndSub

PublicSub DisplayRequest(ByVal req As HttpWebRequest)

Trace.WriteLine("*** Request Start ***")

Trace.WriteLine(req.RequestUri.ToString())

DisplayHeaders(req.Headers)

Trace.WriteLine("*** Request End ***")

EndSub

PublicSub DisplayResponse(ByVal hresp As HttpWebResponse)

Trace.WriteLine(
Nothing)

Trace.WriteLine("*** Response Start ***")

Trace.WriteLine(hresp.StatusCode)

Trace.WriteLine(hresp.StatusDescription)

DisplayHeaders(hresp.Headers)

DisplayContent(hresp)

Trace.WriteLine("*** Response End ***")

Trace.WriteLine(
Nothing)

EndSub

PublicSub DisplayHeaders(ByVal headers As NameValueCollection)

Dim sItem AsString

ForEach sItem In headers

Trace.WriteLine(sItem & ": " & headers(sItem))

Next

EndSub

PublicSub DisplayContent(ByVal response As HttpWebResponse)

Dim strm As Stream = response.GetResponseStream()

IfNot IsNothing(strm) Then

Dim sr As StreamReader = New StreamReader(strm, Encoding.ASCII)

Trace.WriteLine(sr.ReadToEnd())

EndIf

EndSub

PublicSub GetData(ByVal url AsString, _

ByVal contentType AsString, _

ByVal method AsString, _

ByVal content AsString, _

ByValParamArray headers() AsString)

Dim req As HttpWebRequest = WebRequest.Create(url)

Dim header AsString

Dim s As Stream

ForEach header In headers

req.Headers.Add(header)

Next

If method.Length > 0 Then

req.Method = method

EndIf

If contentType.Length > 0 Then

req.ContentType = contentType

EndIf

If content.Length > 0 Then

req.ContentLength = content.Length

s = req.GetRequestStream

Dim sw As StreamWriter = New StreamWriter(s)

sw.Write(content)

sw.Close()

DisplayRequest(req)

Dim res As HttpWebResponse = req.GetResponse

DisplayResponse(res)

EndIf

EndSub

PublicFunction BuildSOAPMessage() AsString

Dim st As MemoryStream = New MemoryStream(1024)

Dim result AsString

Dim buffer() AsByte



Dim tr AsNew XmlTextWriter(st, Encoding.UTF8)

tr.WriteStartDocument()

tr.WriteStartElement("soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/")

tr.WriteAttributeString("xmlns", "xsi",
Nothing, "http://www.w3.org/2001/XMLSchema-instance")

tr.WriteAttributeString("xmlns", "xsd",
Nothing, "http://www.w3.org/2001/XMLSchema")

tr.WriteAttributeString("xmlns", "soap",
Nothing, "http://schemas.xmlsoap.org/soap/envelope/")

tr.WriteStartElement("Body", "http://schemas.xmlsoap.org/soap/envelope/")

'Lab 03 Exercise 4

'Insert code here

tr.WriteStartElement(Nothing, "GetAccount", "http://tempuri.org")

tr.WriteEndElement()

tr.WriteEndElement()

tr.WriteEndDocument()

tr.Flush()

buffer = st.GetBuffer()

Dim d As Decoder = Encoding.UTF8.GetDecoder()

Dim chars() AsChar

ReDim chars(buffer.Length)

d.GetChars(buffer, 2, buffer.Length - 2, chars, 0)

tr.Close()

st.Close()

BuildSOAPMessage = result

EndFunction



End
Module



 
Last edited:
Back
Top