I want to get Network Interface on which HttpWebRequest was made
I found WebRequestExtensions.GetCurrentNetworkInterface function for this. HttpWebRequest also has GetCurrentNetworkInterface() method to perform the same.
This is my code:
HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(new Uri(Url, UriKind.Absolute));
//this line throws InvalidOperationException
NetworkInterfaceInfo i = httpWebRequest.GetCurrentNetworkInterface();
I perform method call from UI thread. If I made call after BeginGetResponse exception tells “request was finished”. What is workaround for this?
Exception info:
Message is InvalidOperationException
StackTrace:
at System.Net.Browser.ClientHttpWebRequest.GetConnectionDetails(IntPtr& Details, Int32& sizeofDetails)
at Microsoft.Phone.Net.NetworkInformation.WebRequestExtensions.GetCurrentNetworkInterface(WebRequest request)
I had a similar problem recently and found you can’t call
GetCurrentNetworkInterfacebeforeBeginGetResponse(because the connection hasn’t been made) but if you call it within theBeginGetResponsecallback the request has already completed and you get the “Web request is already finished” error.ADDED by question-starter:
Fully-worker code which allows to get
NetworkInterfaceInfoofHttpWebRequestfrom background thread (usedBackgroundWorkerin this example to simulate this):ADDED AFTER FULL-DAY DEBUGGING:
I can’t make it work 100% time, especially when loaded page is small. In this situation “request is finished” appears all the time. But with large loaded page it works even without
EventWaitHandle