【问题标题】:System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailureSystem.Net.WebException:获取响应流时出错 (ReadDone2):ReceiveFailure
【发布时间】:2016-06-20 20:40:20
【问题描述】:

我正在 Visual Studio 中使用 Xamarin 创建一个 android 应用程序,但最终出现错误:

“System.Net.WebException:获取响应流时出错(ReadDone2): 接收失败”。

这发生在我创建的服务尝试返回一个列表但最终在我的 CompletedEventArgs 结果调用处停止。我的 Android 应用程序有一个代理客户端,它调用与 SQL Server 通信的 WCF 服务。我的代码如下:

private void ClientOnGetTransactionsCompleted(object sender, GetTransactionsCompletedEventArgs e)
    {
        transactions = new List<TransactionInterface>();
        try
        {
            Console.Out.WriteLine(e.Result.Length);
            for (int i = 0; i < e.Result.Length; i++)
            {
                transactions.Add((TransactionInterface)e.Result[i]);
            }
            RunOnUiThread(() => list.Adapter = new AccountAdapter(this, transactions));
        }
        catch(System.Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }

我正在尝试使用属于 TransactionInterface 的两个不同对象填充一个列表。我可以从我的活动中很好地填充列表,但是当我调用服务时它会失败。我的服务代码是这样的:

public List<TransactionInterface> GetTransactions(string id)
    {
        DataClasses1DataContext context = new DataClasses1DataContext();

        var tollQuery = from t in context.Tolls
                        where t.account_id.Equals(id)
                        select new InterfaceTollTest(t.status_time, t.fee, t.plate_id); 
        var paymentQuery = from p in context.Payments
                           where p.account_id.Equals(id)
                           select new InterfacePaymentTest(p.status_time, p.payment1, p.credit_type);
        var tolls = tollQuery.ToList();
        var payments = paymentQuery.ToList();
        var all = new List<TransactionInterface>();
        System.Console.WriteLine("Bunny Rabbit");
        for (int i = 0; i < tolls.Count; i++)
        {
            all.Add(tolls[i]);
        }

        for (int i = 0; i < payments.Count; i++)
        {
            all.Add(tolls[i]);
        }

        return all;
    }

我已经测试了我的代码以检查我的查询是否正常工作并且它是否按预期返回所有内容。也许我在服务中错误地投射它,但我在 Activity 中尝试了同样的事情来填充列表并且它工作正常。 CompletedEventArgs 返回 object[] 并且我将其修改为也返回 List 但这没有帮助。我尝试了这两种方法,看看我是否得到了结果,它只是因为同样的错误而停止了。

Console.WriteLine(e.Result.Length);
Console.WriteLine(e.Result.Count);

我不确定我是否只是忽略了一些小错误,但我们将不胜感激。

【问题讨论】:

    标签: c# android wcf xamarin.android


    【解决方案1】:

    我知道出了什么问题。这里的问题是 WCF 测试客户端不支持我的 GetTransactions 服务,因为它使用类型 System.Object[]。由于我使用 SLsvcUtil 创建代理客户端,因此它没有显示错误所在的following screen。为了让它工作,在我的服务中为我想添加到我的列表中的对象创建了一个 DataContract。希望这可以帮助其他人解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      相关资源
      最近更新 更多