底层连接已关闭:接收时发生意外错误

时间:2012-04-27 08:01:20

标签: c# linq web-services rest entity-relationship

这是一个跟进问题:linq issue with creating relationships关于我收到的答案。我不确定发生了什么,但我收到了一个错误:

The underlying connection was closed: An unexpected error occurred on a receive.

这就是异常发生的地方:

    string uriGroup = "http://localhost:8000/Service/Group";
    private void ListGroups_Click(object sender, RoutedEventArgs e)
    {
        XDocument xDoc = XDocument.Load(uriGroup); // this line
        var groups = xDoc.Descendants("Group")
            .Select(n => new
            {
                GroupName = n.Element("GroupName").Value,
                GroupHeader = n.Element("GroupHeader").Value,
                TimeCreated = DateTime.Parse(n.Element("TimeAdded").Value),
                Tags = n.Element("Tags").Value, 
                Messages = n.Element("GroupMessages").Value
            })
            .ToList();

        dataGrid2.ItemsSource = groups;
    }

1 个答案:

答案 0 :(得分:10)

由于您要返回List个对象,因此您可能已超过MaxItemsInObjectGraph。您可以通过修改web.config(或app.config)来增加该值:

<behaviors>
    <behavior>
        <dataContractSerializer maxItemsInObjectGraph="6553600" />
    </behavior>
</behaviors>

您可能还想考虑一下常见的嫌疑人:

  • <readerquota>
  • MaxReceivedMessageSize
  • MAXBUFFERSIZE
  • MaxBufferPoolSize

您应该启用WCF Tracing,因为它会包含更详细的错误。是的,这适用于自托管应用程序。