[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.
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
Re: WCF Webhook Service, How to convert POST stream to data array?
Originally Posted by Lightning
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