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

耗尽温柔 提交于 2020-01-15 03:07:32

问题


This is a follow up question from here: linq issue with creating relationships in regards to the answer I recieved. Im not sure what has happend but I get an error:

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

And this is where the exception happens:

    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:


Since you are returning a List of objects, it is possible that you have exceeded the MaxItemsInObjectGraph. You can increase the value by modifying your web.config (or app.config):

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

You may also want to consider looking at the usual suspects:

  • <readerquota> values
  • MaxReceivedMessageSize
  • MaxBufferSize
  • MaxBufferPoolSize

You should enable WCF Tracing as it will contain more detailed errors. Yes, this works even for self-hosted apps.



来源:https://stackoverflow.com/questions/10346968/the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-receive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!