954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

webrequest - soap action header

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

Eregnon
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 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

kronald
Newbie Poster
6 posts since May 2010
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: