0

Good evening, I am attempting to build a WCF service that will listen for a webhook call from a website, in my case www.formstack.com. I am able to get the WCF service working and accepting data but the stream and/or message format is being returned as a long URL formatted text string instead of XML. I have looked in to formstack and it does not have any other way to format the message.

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.&Would+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?

This is my current 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 and decode/parse it, or 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

1 Answer 1

0

I thought I would submit the accepted solution. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.