0

I'm trying to use the web request class in vb.net to post some xml. On the reciving end, I keep getting an internal server error with the message: Missing Soap action header". I did some reasearch and saw that a firewall can strip out the soap action header so I tried running it with no firewall and got the same result. I tried adding a soap action header using the header command, and that didn't even get to the server to receive an error message. Can anyone tell me how to add the soap action header? Code is below:


Public Sub PostToWebsite(ByVal sData As String)
Dim oRequest As WebRequest = WebRequest.Create(cDestinationURL)
oRequest.Method = "POST"

'convert data to a byte array
Dim bArray As Byte() = Encoding.UTF8.GetBytes(sData)

'set content type
oRequest.ContentType = "application/x-www-form-urlencoded"

' soap action (this is the header I tried to add. Didn't work.)
' oRequest.Headers.Add("SOAPAction", "\ \ ")

' Set the ContentLength property of the WebRequest.
oRequest.ContentLength = bArray.Length

' Get the request stream.
Dim dataStream As Stream = oRequest.GetRequestStream

Try
' Write the data to the request stream.
dataStream.Write(bArray, 0, bArray.Length)


Catch ex As Exception
cPostResponse = "Error Sending Data: " & ex.Message
Exit Sub
End Try

' Close the Stream object.
dataStream.Close()

Try
' Get the response.
Dim oResponse As WebResponse = oRequest.GetResponse()
dataStream = oResponse.GetResponseStream()

Catch ex As Exception
cPostResponse = "Error Getting Response: " & ex.Message
Exit Sub
End Try

' Get the stream containing content returned by the server.

' Open the stream using a StreamReader for easy access.
Dim oReader As New StreamReader(dataStream)

' Read the content.
cPostResponse = oReader.ReadToEnd()

' Clean up the streams.
oReader.Close()
dataStream.Close()

End Sub

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by kronald
0

The second parameter needs to be a URI. I changed three lines in your code and it works just fine.

Dim oRequest As WebRequest = webRequest.Create("http://www.webservicex.net/stockquote.asmx")

        oRequest.ContentType = "text/xml" 
        oRequest.Headers.Add("SOAPAction", "http://www.webserviceX.NET/GetQuote")

and sData =

<?xml version="1.0" encoding="utf-8"?>
	<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Body>
		<GetQuote xmlns="http://www.webserviceX.NET/">
			<symbol>HD</symbol>
		</GetQuote>
	</soap:Body>
</soap:Envelope>"

Hope that helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.