Problem with asynchronous HttpWebRequest

A

Assaf Shemesh

Hi,

I'm having a problem with asynchronous HttpWebRequest. It's a simple
http client-server. For most of my users it works fine. However, some
of them get the exception:

System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: The attempted operation is not
supported for the type of object referenced
at System.Net.Sockets.Socket.get_ConnectEx()
at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP,
Boolean flowContext, AsyncCallback callback, Object state)
at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP,
AsyncCallback callback, Object state)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress&
address, ConnectSocketState state, IAsyncResult asyncResult, Int32
timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
asyncResult)

My code is:

Uri url = new Uri(getURI());
m_request = (HttpWebRequest)WebRequest.Create(url);
m_request.Credentials = CredentialCache.DefaultCredentials;
m_request.UserAgent = getUserAgent();
m_request.BeginGetResponse(new AsyncCallback(ProcessResponse), null);

and then:

private void ProcessResponse(IAsyncResult asynchronousResult) {
HttpWebResponse response =
(HttpWebResponse)m_request.EndGetResponse(asynchronousResult);
Stream stream = response.GetResponseStream();
....
}

This is so weird.
Any ideas ?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top