问题
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