# .NET and More > WPF, WCF, WF >  [RESOLVED] WCF Webhook Service, How to convert POST stream to data array?

## BKSwindell

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?


```
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

----------


## Lightning

You could simple parse the parameters with something like:

undefined Code:
Dim pairs As New List(Of KeyValuePair(Of String, String))()Dim keyValuePairs() As String = INPUT.Split("?"c)(1).Split("&"c)For Each pair As String In keyValuePairs    Dim kp() As String = pair.Split("="c)    pairs.Add(New KeyValuePair(Of String, String)(kp(0), kp(1)))Next pair
Where INPUT is the string you recieve. Or you could try to use HttpUtility.ParseQueryString(INPUT)

----------


## BKSwindell

> 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. 



```
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

----------

