gpt4 book ai didi

c# - 使用 WebClient 的 wp7 REST 服务调用超时异常

转载 作者:行者123 更新时间:2023-11-30 12:14:47 25 4
gpt4 key购买 nike

编辑:我很乐意放弃这个问题的赏金 - 时间快到了 - 下面的所有评论都是最新的,但仍然没有解决。

出现奇怪的错误。我已将我的代码简化为绝对最简单的形式,但对于以下代码仍然出现错误。

    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 在浏览器请求时起作用。此外,上述代码在控制台应用程序中调用时工作正常,同样的 URL 和类似代码在 Monodroid 中也工作正常。

最后,服务源非 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]

最佳答案

也许试试:webClient.DownloadStringAsync(yourUrl);

代替

webClient.OpenReadAsync(yourUrl);

关于c# - 使用 WebClient 的 wp7 REST 服务调用超时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8885600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com