Solved

Read Continuous STream of XML

Posted on 2013-06-19
7
310 Views
Last Modified: 2013-06-24
I am trying to figure out the best way to consume a continuous stream of XML data from a service that is sending the data as a "constant" feed over HTTP.

I was considering using HttpWebRequest/Response but I am not sure how that will behave if the data just continuously streams.

Any thoughts?
0
Comment
Question by:lrbrister
  • 3
  • 3
7 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39261941
do u know when the stream is ended, i mean when the xml is response was fully received?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39261951
0
 

Author Comment

by:lrbrister
ID: 39262292
sedgwick,
 I've implemented that

I get the initial response and then after 10 seconds or so the thread exits

I need that to stay open

I see in the example code this comment in the Main section...

        ' Keep the main thread from continuing while the asynchronous
        ' operation completes. A real world application
        ' could do something useful such as updating its user interface.
        allDone.WaitOne()

How do I keep this open???
That is what is killing me

Here's what is supposed to happen
This is a VOIP Phone system and my POST starts the monitoring process on a phone
I start to request by posting some xml to the URL
I get an initial response on that connection pretty much saying "Monitoring"
The connection stays open
Anything done on that phone causes more xml to come in on that same connection (thread?)

I'm getting the initial response...
I am not getting the following response streams

Seems to me this part should be changed in the
GetResponseCallback(ByVal asynchronousResult As IAsyncResult) ???

        Dim streamResponse As Stream = response.GetResponseStream()
        Dim streamRead As New StreamReader(streamResponse)
        Dim responseString As String = streamRead.ReadToEnd()


        Debug.WriteLine(responseString)
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 42

Expert Comment

by:sedgwick
ID: 39262682
u mean the allDone.WaitOne() is signald but the stream is partial?
0
 

Author Comment

by:lrbrister
ID: 39262991
sedgewick,
  I guess...I'll try and explain the issue.
Sorry for any non sensical verbiage...

The Async is working
I post my xml command to the vendors server and get a response.
My command is basically "Start monitoring this phone number"  (Our VOIP System)

Their initial response is "yep...we're monitoring"
And I get this back
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<org.m5.api.v1.Response xmlns:m5="http://www.m5net.com/org/m5/data/v2/cti" xmlns:csta="http://www.ecma-international.org/standards/ecma-323/csta/ed5">
    <ErrorCount>0</ErrorCount>
    <Id>1</Id>
    <Result xsi:type="org.m5.data.v2.cti.HostedConnectObject" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <csta:MonitorStartResponse>
            <csta:monitorCrossRefID>400</csta:monitorCrossRefID>
        </csta:MonitorStartResponse>
    </Result>
</org.m5.api.v1.Response>

After I get this is where my current code is exiting from the process

But what is SUPPOSED to happen is

If my phone makes a call or receives one...the vendor sends me additional xml "chunks"

If nothing happens on my phone I get a "still monitoring" every 30 seconds

In any case I get additional xml at the most every 30 seconds
Example
<command>
  csta:monitorCrossRefID>400</csta:monitorCrossRefID>
</command>

The ongoing stream is what I'm not getting
My thread exits
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39270879
Try setting the KeepAlive property of request to true and then call the responsestream.read in a loop.
0
 

Author Closing Comment

by:lrbrister
ID: 39271351
That did it.
Thanks
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question