Results 1 to 5 of 5

Thread: Check WebResponse Status

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    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?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    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:
    1. Imports System.Net
    2.  
    3. Public Class MainForm
    4.  
    5.     Private Sub SomeRequest()
    6.         ' Request here....
    7.  
    8.         Try
    9.             Response = TryCast(Request.GetResponse(), HttpWebResponse)
    10.         Catch wex As WebException
    11.             ' Handle
    12.         Catch ex As Exception
    13.             ' Handle
    14.         End Try
    15.  
    16.         If Response.StatusCode <> HttpStatusCode.OK Then
    17.             ' Handle
    18.         End If
    19.  
    20.         Dim source As String = Nothing
    21.  
    22.         Using resposeStream As Stream = Response.GetResponseStream()
    23.             Using resposeReader As New StreamReader(resposeStream)
    24.                 source = resposeReader.ReadToEnd()
    25.             End Using
    26.         End Using
    27.     End Sub
    28. End Class

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    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?

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    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:
    1. Imports System.Net
    2. Imports System.Xml
    3.  
    4. Public Class MainForm
    5.  
    6.     Private Sub DownLoad()
    7.         Dim url As String = "path"
    8.         Dim xDoc As New XmlDocument
    9.         xDoc.Load(url)
    10.  
    11.         For Each cNode In xDoc.ChildNodes.Cast(Of XmlNode)()
    12.             MessageBox.Show(cNode.InnerText)
    13.         Next
    14.     End Sub
    15.  
    16. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width