Results 1 to 3 of 3

Thread: [RESOLVED] WCF Webhook Service, How to convert POST stream to data array?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Location
    Deer Park, NY
    Posts
    113

    Resolved [RESOLVED] WCF Webhook Service, How to convert POST stream to data array?

    Good afternoon, I am attempting to build a WCF service that will listen for a webhook call from as website, in my case www.formstack.com. I am able to get the WCF service working and accepting data but the stream is being returned as a long URL formatted text string instead of XML.

    This is what is being returned. I ultimately need this into a format that I can then submit it to a database.
    FormID=1730225&UniqueID=166942101&Ticket+Number=&System+Number=&Customer+Number=&Customer+Name=&Your +Name=Brad+Swindell&Email=&Score=10+-+Very+Likely&Additional+Feedback=This+is+%22A+Test%22%2C+that+has+%3D+and+%26+symbol%27s+in+it.&Woul d+you+like+this+survey+to+be+anonymous%3F=No&Tech=&Id=
    I could try to parse the text by & and = and then replace the +. but I would have to trap every other symbol. Is there a better way to approach this issue?
    Code:
    Public Function PostSampleMethod(data As Stream) As String Implements IMyService.PostSampleMethod
            Dim reader As New StreamReader(data)
            Dim xmlString As String = reader.ReadToEnd()
    
            Using w As StreamWriter = File.AppendText("C:\log.txt")
                Log(xmlString, w)
            End Using
    
            Return Nothing
    End Function
    Formstack Webhook API - https://www.formstack.com/developers/webhooks

    I was wondering if VB.Net has a library that can handle this process or if I am going about getting the data from the POST the wrong way?

    Any help would be appreciated.

    Thanks guys for the help.

    Brad Swindell
    Attached Files Attached Files

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: WCF Webhook Service, How to convert POST stream to data array?

    You could simple parse the parameters with something like:
    undefined Code:
    1. Dim pairs As New List(Of KeyValuePair(Of String, String))()
    2. Dim keyValuePairs() As String = INPUT.Split("?"c)(1).Split("&"c)
    3. For Each pair As String In keyValuePairs
    4.     Dim kp() As String = pair.Split("="c)
    5.     pairs.Add(New KeyValuePair(Of String, String)(kp(0), kp(1)))
    6. Next pair
    Where INPUT is the string you recieve. Or you could try to use HttpUtility.ParseQueryString(INPUT)
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Location
    Deer Park, NY
    Posts
    113

    Resolved Re: WCF Webhook Service, How to convert POST stream to data array?

    Quote Originally Posted by Lightning View Post
    Or you could try to use HttpUtility.ParseQueryString(INPUT)
    Thanks Lightning, that is the solution that I have accepted. The HttpUtility class does the work of parsing the POST data in to a NameValueCollection that can then be retrieved individually.

    Code:
    Public Function PostSampleMethod(data As Stream) As String Implements IMyService.PostSampleMethod
            Dim reader As New StreamReader(data)
            Dim xmlString As String = reader.ReadToEnd()
    
            Dim httpResponse As NameValueCollection = HttpUtility.ParseQueryString(xmlString)
    
            For i As Integer = 0 To httpResponse.Count - 1  
                Debug.WriteLine("{0} - {1}", {httpResponse.Keys(i), httpResponse.Item(i)})
            Next 
    
            Using w As StreamWriter = File.AppendText("C:\log.txt")
                Log(httpResponse.Get("FormID"), w)
                Log(httpResponse.Get("UniqueID"), w)
                Log(httpResponse.Get("HandshakeKey"), w)
            End Using
    
            Return Nothing
    End Function
    Brad Swindell

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