Solved

Read Continuous STream of XML

Posted on 2013-06-19
7
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

705 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