Today, when using WCF to return an object, an error was encountered: The underlying connection was closed: An error occurred while receiving. After a large half-day of the investigation, turned out to be a humble thing in mischief:
This. Configuration.proxycreationenabled = true;
It is true in the above code that causes the program to error, and then it resolves the problem by changing the true to False.
Microsoft's official explanation for proxycreationenabled is that even using this flag to create a proxy will only set up a proxy for the actual type that conforms to the requirements of the acting proxy. Therefore, it may be because my serialized object does not conform to the proxy requirements. Therefore, the speculation may be because my serialization object does not meet the requirements of the proxy, the specific reasons for future re-check.
Throughout the troubleshooting process, through the online information also learned that the following conditions will also be reported this error:
1. The object that needs to be serialized uses an enumeration type, and the enumeration type is not set [DataContract] or the enumeration value itself is not set [Enummember].
2. When the return type is DataTable, the TableName property is not set.
These two questions can be described in the following: Wuhuacong (Wu Huacong) column
"The underlying connection has been closed: An error occurred on receive" when WCF gets a data object