Timeout exception with wp7 REST service call using WebClient

Edit: I would like to give generosity to this question - time is almost up - all comments below are updated, but there is still no permission.

Getting a weird mistake. I have reduced my code to its absolute simplest form and am still getting an error for the following code.

public partial class MainPage : PhoneApplicationPage { private readonly WebClient webClient; public MainPage() { InitializeComponent(); webClient = new WebClient(); webClient.OpenReadCompleted += clientOpenRead_Completed; } private void LoadButton_Click(object sender, RoutedEventArgs e) { webClient.OpenReadAsync(new Uri(@"validURL")); } private void clientOpenRead_Completed(object sender, System.Net.OpenReadCompletedEventArgs e) { using (var sr = new StreamReader(e.Result)) { Result.Text = sr.ReadToEnd(); } } } 

sr.ReadToEnd (); always returns an empty string, and when I check "e.Result" for clientOpenRead_Completed, it contains the following exception:

 base {"Timeouts are not supported on this stream."} System.SystemException {System.InvalidOperationException} 

Other important checks: validURL runs on browser request. In addition, the above code works fine when called in a console application, and the same URL and similar code work fine in Monodroid.

Finally, the service source is not WCF.

Any ideas?

Thanks.

EDIT: stacktrace at the point where I check e.Result: (from a slightly different project, but with the same problem)

 > AppTest.dll!AppTest.Data.AsyncServiceProvider.clientOpenRead_Completed(object sender, System.Net.OpenReadCompletedEventArgs e) Line 20 C# System.Net.dll!System.Net.WebClient.OnOpenReadCompleted(System.Net.OpenReadCompletedEventArgs e) + 0x15 bytes System.Net.dll!System.Net.WebClient.OpenReadOperationCompleted(object arg) + 0xc bytes mscorlib.dll!System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo rtmi, object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object parameters, System.Globalization.CultureInfo culture, bool isBinderDefault, System.Reflection.Assembly caller, bool verifyAccess, ref System.Threading.StackCrawlMark stackMark) mscorlib.dll!System.Reflection.RuntimeMethodInfo.InternalInvoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture, ref System.Threading.StackCrawlMark stackMark) + 0x168 bytes mscorlib.dll!System.Reflection.MethodBase.Invoke(object obj, object[] parameters) + 0xa bytes mscorlib.dll!System.Delegate.DynamicInvokeOne(object[] args) + 0x98 bytes mscorlib.dll!System.MulticastDelegate.DynamicInvokeImpl(object[] args) + 0x8 bytes mscorlib.dll!System.Delegate.DynamicInvoke(object[] args) + 0x2 bytes System.Windows.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0xc bytes System.Windows.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority priority) + 0x83 bytes System.Windows.dll!System.Windows.Threading.Dispatcher.OnInvoke(object context) + 0x8 bytes System.Windows.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args) + 0x19 bytes System.Windows.dll!System.Windows.Hosting.DelegateWrapper.InternalInvoke(object[] args) + 0x2 bytes System.Windows.RuntimeHost.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam[] pParams, ref System.Windows.Hosting.NativeMethods.ScriptParam pResult) + 0x5e bytes [External Code] 
+4
source share
4 answers

Perhaps try: webClient.DownloadStringAsync (yourUrl);

instead

webClient.OpenReadAsync (yourUrl);

+2
source

Try setting AllowReadStreamBuffering webClient to false before calling OpenReadAsync() .

UPDATE

Based on your comment, I think that you may have the wrong version (not windows phone) of System.Net.dll being referenced, and this may be the cause of the problem. On 7.1 (standard installation) it should be

 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone71\System.Net.dll 

If you are at 7.0, this should be

 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone\System.Net.dll 
+1
source

Have you tried to do the same with an HttpWebRequest with different ContentType and Accept headers?

 HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(@"validURL"); httpWebRequest.Method = "GET"; httpWebRequest.BeginGetResponse((asyncresult) => { try { WebResponse webResponse = httpWebRequest.EndGetResponse(asyncresult); using (Stream stream = webResponse.GetResponseStream()) { StreamReader Reader = new StreamReader(stream); string response = Reader.ReadToEnd(); } } catch (Exception ex) { exception(ex); } }, httpWebRequest); 
+1
source

Is the url host like https? If so, can you try hitting the url from the browser in WP7?

How much data is coming in for this request?

-1
source

Source: https://habr.com/ru/post/1391321/


All Articles