編輯:我很想在這個問題上放棄賞金 - 時間快到了 - 下面的所有評論都是最新的,但仍然沒有解決方案。使用WebClient進行wp7 REST服務呼叫的超時異常
獲得一個奇怪的錯誤。我已經將我的代碼縮減爲絕對最簡單的形式,並且仍然出現以下代碼錯誤。
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();總是返回空字符串,當我從clientOpenRead_Completed檢查「e.Result」它包含以下異常:
base {"Timeouts are not supported on this stream."} System.SystemException {System.InvalidOperationException}
其他重要證據:從瀏覽器請求時validURL工作。另外,上面的代碼在控制檯應用程序中調用時也可以正常工作,Monodroid中也有相同的URL和類似的代碼。
最後,服務源非WCF。
任何想法?
謝謝。
編輯:堆棧跟蹤在我檢查e.Result點:(從稍微不同的項目,但同樣的問題)
> 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]
什麼是異常的堆棧跟蹤? – 2012-01-16 20:15:16
這是一種奇怪的行爲。該應用程序不會崩潰,但點擊按鈕時,不會顯示任何內容。當我遍歷代碼時,e.Result爲空,當我從clientOpenRead_Completed檢查'e.Result'時,它在'e.Result.ReadTimeout'中包含上述異常。我看到異常正在內部處理,但我仍然需要處理它,以便應用程序正常工作。 – IUnknown 2012-01-16 20:41:19
你下載了什麼類型的數據?廣播流? XML? – vidalsasoon 2012-01-16 21:04:07