HTTP Request - SOAP

  • Thread starter Thread starter Jason Carter
  • Start date Start date
J

Jason Carter

A while ago I asked about how to use the HTTPRequest
object for sending a soap request. Somebody responded
with the code that I needed, but I recently lost it and I
really need it back now. Can anybody help me here? I
really this code for my app.

Thanks.
 
Hi Jason,

Go to Google.
Click on Groups.
Click on Advanced.
Put your name in the Author box.

This will bring up all the threads that you posted to.

Regards,
Fergus
 
* "Jason Carter said:
A while ago I asked about how to use the HTTPRequest
object for sending a soap request. Somebody responded
with the code that I needed, but I recently lost it and I
really need it back now. Can anybody help me here? I
really this code for my app.

<http://www.google.de/advanced_group_search>

This group is microsoft.public.dotnet.languages.vb.
 
alright...i think he's learned a nifty recovery tool on google. i usually
don't just blurt out code but i happen to have it just sitting around at
present.

merry christmas.

hth,

steve

' these are particluar to my app...not to making soap requests in general.

Private Const shopCode As String = "XYZ"
Private Const appId As String = "SOME_GENERATED_PUBLIC_KEY"
Private Const syncServer As String = "http://somecompany.com/websvc.php"
' wow...i thought people just used asp in the real world!

' this is as basic as it gets
' the method is getData(shopcode, appid)
' this is how you'd wrap up the request in soap

Function sendWebRequest() As String
Dim webRequest As HttpWebRequest =
CType(webRequest.Create(syncServer), HttpWebRequest)
Dim webResponse As HttpWebResponse
Dim soapEnvelope As String
RaiseEvent CurrentProgress("Creating remote data request", 5)
soapEnvelope &= "<SOAP:Envelope>" & vbCrLf
soapEnvelope &= " <SOAP:Body>" & vbCrLf
soapEnvelope &= " <getData>" & vbCrLf
soapEnvelope &= " <parameters>" & vbCrLf
soapEnvelope &= " <shopcode xsi:type=""xsd:string"">" &
shopCode & "</shopcode>" & vbCrLf
soapEnvelope &= " <appid xsi:type=""xsd:string"">" & appId
& "</appid>" & vbCrLf
soapEnvelope &= " </parameters>" & vbCrLf
soapEnvelope &= " </getData>" & vbCrLf
soapEnvelope &= " </SOAP:Body>" & vbCrLf
soapEnvelope &= "</SOAP:Envelope>" & vbCrLf
With webRequest
.ContentType = "text/xml"
.Headers.Add("SOAPMethodName", "getData")
.ContentLength = soapEnvelope.Length
.Method = "POST"
.Timeout = 60 * 1000 ' milliseconds to seconds
Dim streamWriter As New StreamWriter(.GetRequestStream())
streamWriter.Write(soapEnvelope)
streamWriter.Close()
webResponse = CType(.GetResponse(), HttpWebResponse)
End With
Dim stream As Stream = webResponse.GetResponseStream
Dim streamReader As New StreamReader(stream)
Dim xmlStream As String = streamReader.ReadToEnd
streamReader.Close()
stream.Close()
Return xmlStream
End Function
 
That is an awesome google trick. Thanks guys. And thanks for the
alternative HTTP request code too.

Jason Carter
 
Peter,

I can't seem to get your example to work. I am getting an error on the
Dim streamwriter as new StreamWriter(.GetRequestStream())

Error: An unhandled exception of type
'System.Net.ProtocolViolationException' occurred in system.dll

Additonal information: Cannot send a cont-body with this verb-type.

Jason Carter
 
Nevermind guys, I got it fixed. I accidently forgot to set the method
property to "POST". Now it works.

Jason Carter
 
Back
Top