.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > web client : A blocking operation was interrupted by a call to WSACancelBlockingCall
 

web client : A blocking operation was interrupted by a call to WSACancelBlockingCall

Hi

I am donwloading a bunch of files donwlaoding from HTTPS server via modem. I was getting the following exception intermittently.

System.Net.WebException: The operation has timed out
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at ContentServer.CDownloadManager.download_from_server(String source, String usrName, String passWord, String destPath) in G:\Tests\Content_Server\Content_Server\DownloadManager.cs:line 125 8/27/2009 6:43:37 PM
sat_27-5_01.z Failed 8/27/2009 6:43:37 PM

The trace log for the above exception:
ystem.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 284#284
System.Net.Sockets Verbose: 0 : [3668] Socket#48377572::Receive()
System.Net.Sockets Verbose: 0 : [3668] Data from Socket#48377572::Receive
System.Net.Sockets Verbose: 0 : [3668] 00000000 : 17 03 01 00 12 : .....
System.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 5#5
System.Net.Sockets Verbose: 0 : [3668] Socket#48377572::Receive()
System.Net.Sockets Verbose: 0 : [3668] Data from Socket#48377572::Receive
System.Net.Sockets Verbose: 0 : [3668] 00000005 : B2 32 25 D4 6D F7 99 1A-31 E8 70 BB 9E FE 6D A7 : .2%.m...1.p...m.
System.Net.Sockets Verbose: 0 : [3668] 00000015 : DA 22 : ."
System.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 18#18
System.Net.Sockets Verbose: 0 : [3668] Socket#48377572::Receive()
System.Net.Sockets Verbose: 0 : [3668] Data from Socket#48377572::Receive
System.Net.Sockets Verbose: 0 : [3668] 00000000 : 17 03 01 00 14 : .....
System.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 5#5
System.Net.Sockets Verbose: 0 : [3668] Socket#48377572::Receive()
System.Net.Sockets Verbose: 0 : [3668] Data from Socket#48377572::Receive
System.Net.Sockets Verbose: 0 : [3668] 00000005 : 3C 81 6D 80 6F FB 2D 6E-4D BE 1B 9D 03 E0 1B 35 : <.m.o.-nM......5
System.Net.Sockets Verbose: 0 : [3668] 00000015 : 5D BC 2D B7 : ].-.
System.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 20#20
System.Net.Sockets Verbose: 0 : [3668] Socket#48377572::Receive()
System.Net.Sockets Verbose: 0 : [3668] Data from Socket#48377572::Receive
System.Net.Sockets Verbose: 0 : [3668] 00000000 : 17 03 01 00 32 : ....2
System.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 5#5
System.Net.Sockets Verbose: 0 : [3668] Socket#48377572::Receive()
System.Net.Sockets Verbose: 0 : [3668] Data from Socket#48377572::Receive
System.Net.Sockets Verbose: 0 : [3668] 00000005 : 6F 3A BF B1 81 45 7B 91-C5 13 3B E9 C1 52 C8 DB : o:...E{...;..R..
System.Net.Sockets Verbose: 0 : [3668] 00000015 : 08 33 64 05 42 38 95 8D-63 D4 15 52 4A 1F 8C 48 : .3d.B8..c..RJ..H
System.Net.Sockets Verbose: 0 : [3668] 00000025 : 63 9D 84 F6 61 05 E2 80-91 B2 E5 47 27 : c...a......G'
System.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 45#45
System.Net.Sockets Verbose: 0 : [3668] Socket#48377572::Receive()
System.Net Verbose: 0 : [2204] HttpWebRequest#4418278::Abort(The operation has timed out)
System.Net.Sockets Verbose: 0 : [2204] Socket#48377572::Dispose()
System.Net Error: 0 : [2204] Exception in the HttpWebRequest#4418278:: - The operation has timed out
System.Net.Sockets Error: 0 : [3668] Exception in the Socket#48377572::Receive - A blocking operation was interrupted by a call to WSACancelBlockingCall
System.Net.Sockets Verbose: 0 : [3668] Exiting Socket#48377572::Receive() -> 0#0
System.Net Verbose: 0 : [2204] Exiting HttpWebRequest#4418278::Abort()
System.Net Verbose: 0 : [3668] HttpWebRequest#4418278::Abort(The request was canceled)
System.Net Verbose: 0 : [3668] Exiting HttpWebRequest#4418278::Abort()
System.Net Error: 0 : [3668] Exception in the HttpWebRequest#4418278::EndGetResponse - The operation has timed out
System.Net Verbose: 0 : [3668] HttpWebRequest#4418278::Abort()
System.Net Verbose: 0 : [3668] Exiting HttpWebRequest#4418278::Abort()

My code is :

if

((uri.Scheme == Uri.UriSchemeHttp) || (uri.Scheme == Uri.UriSchemeHttps))

{

try

{

using (WebClient wc = new WebClient())

{

wc.Credentials =

new NetworkCredential(usrName, passWord);

wc.DownloadFile(uri, destPath);

}

return true;

}

catch (WebException ex)

{

if (ex.Status == WebExceptionStatus.NameResolutionFailure)

CFileManager.writeLog("Bad domain name");

else if (ex.Status == WebExceptionStatus.ProtocolError)

{

HttpWebResponse response = (HttpWebResponse)ex.Response;

CFileManager.writeLog(response.StatusDescription);

if (response.StatusCode == HttpStatusCode.NotFound)

CFileManager.writeLog("Not Found");

}

else

CFileManager.writeLog(ex.ToString());

return false;

}

}

Any help is highly appreciated.

Regards
Raju

  •  
Siravuri

HttpWebRequest has a default timeout of 10 seconds (controlled by HttpWebRequest.Timeout). If the request does not complete within the Timeout, HttpWebRequest aborts it. This is what you are is seeing (as evidenced by the Abort in the system.net trace). The solution for his problem is to set the Timeout to something larger than the amount of time you expect the download to take. Unfortunately, I can't see an easy way to do this with WebClient - you'll have to use HttpWebRequest directly, or create a class derived from WebClient and override GetWebRequest:

protected override WebRequest GetWebRequest(Uri address)
{

WebRequest request = base.GetWebRequest(address);

request.Timeout = -1; // don't use the timeout at all (beware of misbehaving servers!)
}

Neither HttpWebRequest nor WebClient supports resumable downloads directly. You can use HttpWebRequest.AddRange to add a header telling the server that you only want to download a portion of a file, but it's up to you to keep track of how much of the file you've downloadedand what part you need to redownload.

Oleksii Prokopchuk [NCL]
Since you are downloading over modem, there might be high latency that might be causing the timeouts.

You can get a network sniff using wireshark and confirm if that is the case.

Also, try playing around with the various timeouts (esp the ReadTimeout) on the WebRequest to see if you can get it to work.

If the timeout doesnt work, you will have to retry the request. You can use the HTTP "Range" header to request the part of the data that you need, that way you dont have to download the whole thing again.
feroze
--
http://ferozedaud.blogspot.com
http://blogs.msdn.com/feroze_daud
Feroze Daud

HttpWebRequest has a default timeout of 10 seconds (controlled by HttpWebRequest.Timeout). If the request does not complete within the Timeout, HttpWebRequest aborts it. This is what you are is seeing (as evidenced by the Abort in the system.net trace). The solution for his problem is to set the Timeout to something larger than the amount of time you expect the download to take. Unfortunately, I can't see an easy way to do this with WebClient - you'll have to use HttpWebRequest directly, or create a class derived from WebClient and override GetWebRequest:

protected override WebRequest GetWebRequest(Uri address)
{

WebRequest request = base.GetWebRequest(address);

request.Timeout = -1; // don't use the timeout at all (beware of misbehaving servers!)
}

Neither HttpWebRequest nor WebClient supports resumable downloads directly. You can use HttpWebRequest.AddRange to add a header telling the server that you only want to download a portion of a file, but it's up to you to keep track of how much of the file you've downloadedand what part you need to redownload.

Oleksii Prokopchuk [NCL]

You can use google to search for other answers

Custom Search

More Threads

• FTP in .NET, get list of only subfolders or only files
• Beware BeginAccept: .NET implementation of an asynchronous sockets fail?
• Rate limitation on reception of UDP messages
• SMTP sending failure on windows service
• Sending signed and encrypted S/MIME (PKCS 7) mail with .net
• SSL and Server Certificates
• Server-client discovery without port forwarding
• NetworkStream.BeginWrite - very slow!?!
• Why the delayed response when an invalid hostname is sent to the DNS server?
• function VB.Net for download from ftp - it don't goes to end everytime