Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 401649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:03:12+00:00 2026-05-12T17:03:12+00:00

I’m working on a web application that needs to frequently poll the server database

  • 0

I’m working on a web application that needs to frequently poll the server database and check for any available data to the client.

Ideally, I would need to be able get a javascript function callback in the server, in order to be able to call the javascript function back whenever any new data is available on the database, instead of having to poll the server every 5 seconds.

Simplifying, I would need to be able to call a method in the server and pass a js function as a parameter for callback. I want to avoid the overhead of polling the server repeatedly.

Is there any way this could be possibly done with asp.net and ajax?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:03:12+00:00Added an answer on May 12, 2026 at 5:03 pm

    The alternative that you’re speaking about is some form of COMET style interface, where the client makes a request and the server holds on to it until it has a response. WCF has the PollingDuplex binding type, but I’m not terribly certain how to go about implementing it in javascript.

    Well, this appears to be a very relevant link. It says Silverlight all over it, but it’s an specifically for an AJAX browser application:
    http://www.silverlightshow.net/news/AJAX-Client-for-HTTP-Polling-Duplex-WCF-Channel-in-Microsoft-Silverlight-3-.aspx

    UPDATE:
    I don’t understand why all the alternate answers amount to “omg do polling on your own!” We have modern frameworks and protocols specifically to reduce to the amount of manual code we write. The PollingDuplex functionality provided by WCF does exactly what you want, and the link I provided implements the client side of that system in pure javascript.

    Not sure what more you could want.

    UPDATE 2:

    Sorry, original article link. We all recognize that polling is the only solution for HTTP folks. The primary difference that the author is looking for is simulated push vs constant polling. You can achieve simulated push by placing a long running polling request to the server. With the right server architecture in place, it’ll hold onto that request until it has data. Then it’ll respond. At that point, the client immediately re-requests. In this manner, you utilize the existing HTTP request-response cycle to simulate “pushing” to the client.

    This is primarily accomplished by having the appropriate server architecture in place. That way your requests are put to sleep and woken up in the appropriate manner. This is a far better paradigm than a manual polling answer where you ask the server for updates every 5 seconds. Chatty applications where you want responses now and not 4.8s from now is what
    I’m talking about. Manual polling (making a request for new data every 5s) gives the appearance of being laggy and during periods where no data is updated, it causes unnecessary request/response cycles.

    From the article:

    sl3duplex.js is a reusable,
    stand-alone JavaScript library
    that
    implements the client side of the HTTP
    polling duplex protocol compatible
    with the PollingDuplexHttpBinding in
    System.ServiceModel.PollingDuplex.dll

    From the .HTM file in the download:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>AJAX client for HTTP polling duplex WCF channel in Microsoft Silverlight 3</title>
    
        <script src="sl3duplex.js"></script>
    
        <script src="pubsub.js"></script>
    
        <script language="javascript">
            var sl3duplex = org.janczuk.sl3duplex;
            var proxy = null;
    
            function addNotification(text) {
                var notifications = document.getElementById("notifications");
                notifications.value += text + "\n";
                notifications.scrollTop = notifications.scrollHeight;
            }
    
            function alignUIWithConnectionState(connected) {
                document.getElementById("topicName").disabled =
                   document.getElementById("subscribeButton").disabled = connected ? "disabled" : null;
                document.getElementById("publishText").disabled = connected ? null : "disabled"            
            }
    
            function onSubscribe() {                        
                proxy = new sl3duplex.Sl3DuplexProxy({
                    url: window.location.href.substring(0, window.location.href.lastIndexOf("/")) + "/PubSubService.svc",
                    onMessageReceived: function(body) {
                        addNotification("SERVER NOTIFICATION: " + (new sl3duplex.NotificationMessage(body)).text);
                    },
                    onError: function(args) {
                        addNotification("ERROR: " + args.error.message);
                        alignUIWithConnectionState(false);
                    }
                });
    
                alignUIWithConnectionState(true);
    
                var topic = document.getElementById("topicName").value;
                proxy.send({ message: new sl3duplex.SubscribeMessage(topic),
                             onSendSuccessful: function(args) {
                                 addNotification("CLIENT ACTION: Subscribed to topic " + topic);
                             }
                           });
            }
    
            function onPublish(event) {
                if (event.keyCode == 13) {
                    var publishText = document.getElementById("publishText");
                    var content = publishText.value;
                    publishText.value = "";
                    var topic = document.getElementById("topicName").value;
    
                    proxy.send({ message: new sl3duplex.PublishMessage(topic, content),
                                 onSendSuccessful: function(args) {
                                     addNotification("CLIENT ACTION: Published to topic " + topic + ": " + content);
                                 }
                               });                               
                }
            }
        </script>
    
    </head>
    <body bgcolor="Tomato">
        <table style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;"
            cellspacing="2" align="center">
            <tr>
                <td colspan="2">
                    Topic to subscribe and publish to:
                </td>
            </tr>
            <tr>
                <td style="width: 448px">
                    <input id="topicName" type="text" value="Dante" style="width: 100%" />
                </td>
                <td style="width: 192px">
                    <input id="subscribeButton" type="button" value="Subscribe" style="width: 100%" onclick="onSubscribe();" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan=2>
                    Notifications:
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <textarea id="notifications" name="S1" rows="18" readonly="readonly" style="width: 100%;
                        background-color: ButtonFace"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    Enter text to publish and press Enter:
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input id="publishText" type="text" style="width: 100%" disabled="disabled" onkeypress="onPublish(event);" />
                </td>
            </tr>
        </table>
    </body>
    </html>
    

    There’s no silverlight objects being created or libraries being referenced. I can dump the .JS files into here as well, to show that it is merely a “reusable, stand-alone JavaScript library that implements the client side of the HTTP polling duplex protocol” and didn’t hinge on silverlight being installed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 348k
  • Answers 348k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You will need to add a parameter to the Object… May 14, 2026 at 6:34 am
  • Editorial Team
    Editorial Team added an answer You have to use Win32 API for this. [DllImport("user32.dll")] static… May 14, 2026 at 6:34 am
  • Editorial Team
    Editorial Team added an answer To test whether this particular distribution is consistent with the… May 14, 2026 at 6:34 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.