DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 09 Aug 2007 00:10:02 -0500,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    APA


Async WebRequest isn't asynchronous?   
I have developed a simple webrequest method that will call a remote service from one of my web pages.  The call is part of a class in a separate 
assembly.  The web request code is a pretty basic async call:

         HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(EndPointURL);
         webRequest.Method = "POST";
         webRequest.ContentType = "application/x-www-form-urlencoded";
         webRequest.ContentLength = data.Length;
         Stream strm = webRequest.GetRequestStream();
         strm.Write(data, 0, data.Length);
         strm.Close();

         // For Async Call
         // Create the state object.
         RequestState rs = new RequestState();

         // Put the request into the state object so it can be passed around.
         rs.Request = webRequest;

         // Issue the async request.
         IAsyncResult r = (IAsyncResult)webRequest.BeginGetResponse(new AsyncCallback(RespCallback), rs);

         ThreadPool.RegisterWaitForSingleObject(r.AsyncWaitHandle, new WaitOrTimerCallback(ScanTimeoutCallback), rs, (30 * 1000), true);


The problem is that it doesn't appear to be asynchronous at all.  The page will not finish loading until the web request completes.  A couple of 
things don't make sense here first is the RequestState object (this is code straight from the documentation).  I have no idea what this is doing or 
what it is used for and since it appears to be required why do I have to create it as a custom class instead of there being RequestState class in the 
framework already.  Seems pretty absurd that there is a required object interface that is not even defined in the framework.  The next thing is of 
course why is the page hanging until the request completes?  The code above should immediately return control to the calling page and allow the 
callback handler to handle the response?
Date:Thu, 09 Aug 2007 00:10:02 -0500   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us