.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Asynchronous Web Services, jQuery or .NET (BeginInvoke) Calls?

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net


I have been moving my application to be more AJAX-based.  Currently I have a web service call where I use jQuery to gather some textbox (string) and checkbox (boolean) results and pass it to a web service.  Everything works really well, the response time is super quick.  The only downside that I can see to this is

1) you need to use jQuery, which will add to the user's download time - this doesn't really affect my application too much because I am using jQuery throughout the site

2) users can see the code and potentially try to hack the web service because they know where it is

I am most concerned with #2.  I've been reading a lot about .NET web service calls, using IAsyncResult, http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx, and I am beginning to understand the 4 methods available in this article.  However, is there extra bloat using this way compared to the jQuery web service call?

If there isn't that much bloat or lag time using this method, I'd like to convert my application.  Which one of these 4 methods is best in a scenario where I am just returning a small string value?  The 4 methods in the article are

More Related Resource Links

Making asynchronous calls to web services during ASP.NET page processing

Some ASP.NET web applications use web services to get some data that they display to users. Some pages may lay hardly on web services and these pages need some optimization to work better. In this posting I will show you how to use web services behind your ASP.NET page asynchronously and perform a lot of queries to web services. Sample code included! Eneta.Examples.WebAppThreading.zip VS2008 solution | 60KB Asynchronous page processing As an introduction let's see how ASP.NET supports asynchronous calls behind pages. Although we can use our own threading mechanism and avoid what is offered by ASP.NET it is more safe and time saving to use ASP.NET own infrastructure. The image on right that I stole from MSDN article Asynchronous Pages in ASP.NET 2.0 shows you how synchronous and asynchronous pages are processed by ASP.NET. I recommend to read this MSDN article because you can find also other methods for asynchronous calls. I will introduce you how to use PageAsyncTask based calls. If you look at diagram on right you can see that asynchronous processing of registered tasks happens between PreRender and PreRenderComplete events in separate threads. If we have data bound controls on our page we have to move data binding to PreRenderComplete event because this is the closest phase of page processing where asynchronous calls are finished.

jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn't called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

jQuery live() and ASP.NET Ajax asynchronous postback

The issue is that normally $(document).ready() is called when the DOM is ready to be manipulated. But this doens't happen after an ASP.NET Ajax asynch postback occurs.

This means that the initial jQuery bindings won't be automatically available after the asynchronous postback is over. I underline "automatically" here because my last post describes more possibilities, how this issue can be worked around.

Using JQuery to perform Ajax calls in ASP.NET MVC

The muscle behind the actual asynchronous calls comes from JavaScript. I looked around at a bunch of existing JavaScript libraries and settled on JQuery because of the way it leverages existing CSS knowledge. The three things that the library should do easily are:

.NET Delegates: Making Asynchronous Method Calls in the .NET Environment


One of the many great features of the .NET Framework is that it has asynchronous infrastructure built in. In .NET you can call any method asynchronously by defining a delegate for the method and calling the delegate's asynchronous methods. This is beneficial to your application because when a synchronous call is made, the calling thread is blocked until the method completes whereas an asynchronous call is made on a different thread, and this allows the original thread to continue its work while the asynchronous call is in progress.This article explains delegates in .NET and how to use them to perform asynchronous calls, eliminating age-old threading problems.

Richard Grimes

MSDN Magazine August 2001

Windows 2000: Asynchronous Method Calls Eliminate the Wait for COM Clients and Servers


Windows 2000 is the first version of COM to support asynchronous method calls, which permit clients to make nonblocking calls to COM objects and objects to process incoming calls without blocking the calling threads. COM clients benefit from asynchronous method calls because they can continue working while waiting for outbound calls to return. Objects benefit because they can queue incoming calls and service them from a thread pool. Our SieveClient and SieveServer sample apps demonstrate how to create and use asynchronous clients and servers in COM-based distributed applications.

Jeff Prosise

MSDN Magazine April 2000

jQuery UI Autocomplete, Web Services and JSON

Hi guys, this is my first post, I´m desperate after wasting 2 days in google and reading forums ans sites. I can´t make it work. I just want to provide the name of cities to show in the autocomplete plugin. Let´s go part by part:WEB SERVICE: I use the Json.Net component to serialize a datasetpublic string ConsultTable(string data) { SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["SqlServerConnection"].ToString()); SqlCommand command = new SqlCommand("SELECT name FROM cities",connection); connection.Open(); DataSet dataset = ToDataSet(command.ExecuteReader()); Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer(); json.NullValueHandling = NullValueHandling.Ignore; json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace; json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore; json.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; json.Converters.Add(new DataSetConverter()); StringWriter sw = new StringWriter(); Newtonsoft.Json.JsonTextWriter writer = new JsonTextWriter(sw); writer.Formatting = Formatting.None; writer.QuoteChar = '"'; json.Se

jQuery calls asmx web service

I have a jQuery method that calls a .asmx web service.  the jquery method only executes one time but the web serivce executes multiple times.  Is there a way this could happen or ways to debug this beyond breakpoints in the c# code and alerts in the jQuery.

Securing AJAX Calls from JQuery (Looking for ideas, suggestions, best practices).



I am working on web application in which all of the data I am submitting back to the server is being done on the client side using JQuery AJAX calls to my .NET web services using JSON.  This works perfectly to enhance my user experience and greatly reduces post backs, etc.

What I am looking for suggestions on is securing the web services being exposed to the client side from being used by anything but my JQuery code on my site.  The security hole that I see here is that since the client-side JQuery can access the web services, so could anything.

Any ideas?  What is the best practice here?


JQuery and web services


I am currently using JQuery to post to action methods in my MVC app.  The methods are quite complicated and since I only know the basics of Javascript and JQuery, if I wanted to use JQuery to make a client side call, would I be able to make a call to a web service to do this?  I am new to all these technologies so not sure about how posting from JQuery to web services etc works! 

How Do I maintain the chronological order in which Asynchronous delegate calls are made?


I have created a basic logging framework for my application that writes log messages to a local text file using an Asynchronous delegate.

My application has many threads running however, and as a result, the order of the log entries in the text file is not chronological.

So I have two competing requirements: on one hand, my WriteToLog() method has to return almost immediately so that it doesn't block in-flight code, while at the same time the log file has to be in chronological order.

Any ideas?  Some of the problems I've encountered are:

1a.  Trying to use a Queue (with a lock{ } around it) to maintain the order seems to result in deadlocks

1b.  Even if I use a Queue, at some point the Queue must be written to disk, so it seems like I'd have to frequently have WriteToLog spin off a "WriteToDisk" like method.

2a.  I've considered instantiating a new thread which polls the Queue from (1a) and writes to disk in a loop, say, every 5 seconds.  I'm leaning more towards this method.

3.  I've looked into log4net and some other stuff but it just seems like overkill, and I'd really like to have my own framework for this seemingly simple task.



Sharepoint solution that calls WCF services has performance issues on production machines


I've a SharePoint solution that consists of set of webparts and other features. The webparts backend call a set of WCF web services. When I tried to install it on a production machine, it has some performance issues, I can open the page and wait for 30 min till it response to me.

If I call the same WCF services from a console application they works fine in both machines, if I creates a SharePoint team site it works fine in both machines, everything works fine on the dev machine.

The WCF services do some CRUD operations in a database and some API calls to SharePoint and PerformancePoint APIs

Development machines Specs:


Windows Server 2008 R2 Enterprise, 64-bit

Calling Asynchronous Web Services


How do I call an asynchronous Web Service, from AJAX, that has been defined according to this article:

How to: Create Asynchronous Web Service Methods 

The AJAX Web Service proxy-generator creates Begin<MethodName> and End<MethodName>... methods instead of just <MethodName>.

Best Regards,
Michael Carr


Notify jquery from server (trigger an asynchronous client side event from the server).



I want to have a code that would establish connection from the server to the jQuery client, to update the front page of the website, when some new data is added to the DB. I of course could have an ajax call from the client on every second to check up the database for any changes, but I am just wondering if there is any way to establish a connection from the server side to the client.

The perfect solution would work like that:

- when the page is open, the client registers itself on the server for changes

- the server (knowing all the registered clients) prompts all of them when a change is done

- if any of the clients does not respond, the server removes the client from the registered list

- clients, update the page contents with the new data from the server

The question is if it is possible? Again, I could make all the clients reconnect to the server every second using ajax, however, this does not seem like a clean solution, and additionally it would put an unnecessary load on the server (e.q. 100 clients requesting update every second).

Thanks in advance,

Jozef A. Habdank

Multiple AJAX calls in JQuery


I am trying to make 2 separate AJAX calls using buttons. What I want to happen is: when Button1 is clicked ProductsTable shows data from the webservice; when Button2 is clicked OthersTable shows its own data from the webservice. But right now, when either button is clicked, nothing shows up. I know the code works if there's only one of them and it's not wrapped around a .click function.

No error messages. ASP.NET 4.0, JQuery 1.4.4. Not using ScriptManager. Not using UpdatePanels.

Code below:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="Scripts/jquery-1.4.4.js" type="text/javascript"></script>
    <script src="Scripts/jquery.tmpl.js" type="text/javascript"></script>
    <script id="ProductsTemplate" type="text/x-query-tmpl">
        <table id="ProductsTemplate">            

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

Installing and Uninstalling Services

Installing and Uninstalling Services.Unlike most projects you create in Visual Studio .NET, Windows Service projects cannot be run directly from the development environment by pressing F5. This is because the service in the project must be installed before the project can run.

You can quickly install your service application by using a command line utility called InstallUtil.exe.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend