HttpWebRequest Open Connection

Posted on 2013-06-04
Last Modified: 2013-06-05
I cannot imagine why this has been so hard for me.

I'm trying to post some XML to a site...which I can do and get the initial response

I then want to keep that connection open indefinately and simply accept whatever data comes at me and pass it along to SQL..

So far, I can my command...and get the initial response and send to SQL.

But I cannot get any subsequent data.

Does this need to be done with Threading?  Async?
I'm lost.
Question by:lrbrister
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
  • 5
  • 4
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39223286
I don't believe this is possible.

The web server gets a request, and returns a response.
To get more responses, you have to send more requests.

Curious to see other experts input on this.

Author Comment

ID: 39223623

It seems to me that as long as I send an HTTP 1.1 command and keep the connection alive and also get chuncked data...that should do it.

Can someone let me know if my logic is flawed, and if so, why


What would another solution be?
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39223655
Possibly async client side java code, using ajax?
..that would be my best guess.
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.


Author Comment

ID: 39223664

Any links to a solution that you know of?
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39223754

I still think this would be a "polling" solution though.  Seems to me the nature of a webserver is to get a url request and return a response.  A client browser renders elements when it gets a response.

Basically, you would be sending requests every "x" milliseconds to a webservice or page..from the client side java code on a timer, and processing the responses client side so the page doesn't have to be reloaded.  This would "appear" to be a continuous connection, though it actually isn't.

In a console or windows app, with a sockets connection, you could process data as it is being recieved..and leave the connection open.  But you're programming for a browser.. I just don't think it's possible, unless someone else can show me it is, that's my answer.

Author Comment

ID: 39223862

This is being done in WinForms.

Do you have an example of a sockets connection to an outside source?
LVL 25

Accepted Solution

Ron Malmstead earned 500 total points
ID: 39223877

Author Closing Comment

ID: 39223903
Just so I have a way in, I think I can get some kind of solution

Whether its a socket...or a "polling" solution.

LVL 25

Expert Comment

by:Ron Malmstead
ID: 39223910
Here's another snippet I found using the WebClient class.
Looks promising...
using (var client = new WebClient())
using (var reader = new StreamReader(client.OpenRead(uri), Encoding.UTF8, true))
    string line;
    while ((line = reader.ReadLine()) != null)

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

751 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