Link to home
Start Free TrialLog in
Avatar of IzzyTwinkly
IzzyTwinklyFlag for United States of America

asked on

Processing Continuous JSON stream using C#

Hi guys,

I am trying to process Continuous(endless) JSON stream using C#.
I wrote the following code for this, but it doesn't display anything but </html> on the screen.
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args){

            var url = "http://localhost/myWebService/endlessJsonStream";

            Task<string> t1 = OnContinuousJason(url);
            Console.Write(t1.Result);
            Console.Read();
         }
         private static async Task<string> OnContinuousJason(string url)
         {
            var client = new HttpClient();
            client.Timeout = TimeSpan.FromMilliseconds( Timeout.Infinite);

             var request = new HttpRequestMessage(HttpMethod.Get, url);
             var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
                
              var body = await response.Content.ReadAsStreamAsync();
              var reader = new StreamReader(body);
              var result = "";
              while (!reader.EndOfStream)
              {
                  result = reader.ReadLine();
              }
              return result;
           }
            
        }    
}

Open in new window


What should I do to see the continuously coming JSON stream?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IzzyTwinkly

ASKER

Hi ste5an,

I don't know what is going on with the production code under the hood.
So with that given URL, I can't display the continuous Json stream?
As I know, wcf and rest are used.

Thanks.
But this is important. You need to ask the developer or vendor.
Hi ste5an,

it's rest and wcf. I got confirmed.