We can use ASP.Net Client Callbacks to invoke Data Service in Asynchronous mode without freezing the UI .
Async ASP.Net and WCF Data Service
Instrucutions Step By Step
- Must read MSDN article http://msdn.microsoft.com/en-us/library/ms178208.aspx before trying this sample
- Create a sample empty ASP.Net wesite (Not Web application)
- Copy all the files to website directory provided in this sample download
- Add a service refernace to your project for Northwid Public OData service http://services.odata.org/Northwind/Northwind.svc/
- Locate the function "public void RaiseCallbackEvent(String eventArgument)" and replace with below mentioned code
C#
public void RaiseCallbackEvent(String eventArgument) { returnValue = "Result from Async Northwind Serice Call"+Environment.NewLine; NorthwindEntities nwEntities = new NorthwindEntities(new Uri("http://services.odata.org/Northwind/Northwind.svc/")); foreach (Product item in nwEntities.Products) { returnValue = returnValue + String.Format("ProductID={0} ProductName={1} Price={2}", item.ProductID, item.ProductName, item.UnitPrice) + Environment.NewLine; } }
Run your application and navigate to http://localhost:22438/WebSite1/ClientCallback.aspx
How Does It Work
- Actaually function LookUpStock() raise an Async call to server
- Call is Routed to ' public void RaiseCallbackEvent(String eventArgument)"
- This function actually raise a query to Northwind Database and build an string with list of product
- This list is returned to server using client call back " public String GetCallbackResult()"
Note : Based on data it may take long time to the result to be appered on UI
This code sample is create to support forum post http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/d31c582d-0fba-4f1f-9573-49d05a199f1f
No comments:
Post a Comment