-
Jun 27th, 2013, 01:38 PM
#1
Thread Starter
Fanatic Member
Check WebResponse Status
I am attempting to submit some SOAP and receive a response back. I have been able to handle catching all of the errors that could occur. However I can't figure out how to parse the data that comes back when the status is 200(a successful attempt) My code for submission is below along with the exception handler. Can someone point me in the right direction for parsing the response data?
Code:
' Get the request stream.
Dim dataStream As Stream = request.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
Dim response As WebResponse
Try
response = request.GetResponse()
Catch ex As WebException
Using errorResponse = ex.Response
If errorResponse IsNot Nothing Then
Using errorReader As New StreamReader(errorResponse.GetResponseStream())
ReturnedData = errorReader.ReadToEnd()
PMResponse(ReturnedData, "orderID")
End Using
End If
End Using
Return
End Try
"...Men will still say THIS was our finest hour"
If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?
-
Jun 27th, 2013, 03:09 PM
#2
Re: Check WebResponse Status
Is there no guide available from the source? Obviously without knowing what information the response is supposed to return it's impossible to even begin to parse it and there is only one authority on that which is the supplier of the response!.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 27th, 2013, 03:29 PM
#3
Re: Check WebResponse Status
Why do you read the response under webexception? How can we tell you how the poarse the data if we cant see the source?
your code should look a little like..
vb Code:
Imports System.Net
Public Class MainForm
Private Sub SomeRequest()
' Request here....
Try
Response = TryCast(Request.GetResponse(), HttpWebResponse)
Catch wex As WebException
' Handle
Catch ex As Exception
' Handle
End Try
If Response.StatusCode <> HttpStatusCode.OK Then
' Handle
End If
Dim source As String = Nothing
Using resposeStream As Stream = Response.GetResponseStream()
Using resposeReader As New StreamReader(resposeStream)
source = resposeReader.ReadToEnd()
End Using
End Using
End Sub
End Class
-
Jun 28th, 2013, 08:18 AM
#4
Thread Starter
Fanatic Member
Re: Check WebResponse Status
ident, the reason that I am using the code that way is because I am a noob at using webservices in VB.net. I usually use vbs to accomplish everything but it is not an option right now. I found some tutorials and articles on how to accomplish what I am attempting to do and followed them to the best of my limited ability. I have accomplished everything but reading the successful response.
The successful response is:
Code:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><AddOrderResponse xmlns="http://sma-promail/">
<AddOrderResult>
<OrderSeqID>1076</OrderSeqID>
<OrderID>special1</OrderID>
</AddOrderResult>
</AddOrderResponse>
</soap:Body></soap:Envelope>
"...Men will still say THIS was our finest hour"
If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?
-
Jun 28th, 2013, 11:44 AM
#5
Re: Check WebResponse Status
So you just want to read a XML document thats online.... On my phone right now but may be some thing like
vb Code:
Imports System.Net Imports System.Xml Public Class MainForm Private Sub DownLoad() Dim url As String = "path" Dim xDoc As New XmlDocument xDoc.Load(url) For Each cNode In xDoc.ChildNodes.Cast(Of XmlNode)() MessageBox.Show(cNode.InnerText) Next End Sub End Class
Last edited by ident; Jun 29th, 2013 at 01:58 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|