Code defining the actionresult class
/// <Summary>
/// Result class for method calling between different sets, mainly used for multi-layer communication in WCF
/// </Summary>
[Serializable]
// [Datacontract]
Public class actionresult: marshalbyrefobject
{
...
}
/// <Summary>
/// Result class (generic version) used for method calling between different sets, mainly used for multi-layer WCF Communication
/// </Summary>
/// <Typeparam name = "T"> type of the returned value </typeparam>
Public class actionresult <t>: actionresult
{
...
}
Define the following method in the WCF Service:
/// <Summary>
/// Submit the cost code to the WCF for saving and return the operation result
/// </Summary>
/// <Param name = "costcode"> Cost Code </param>
/// <Returns> whether the operation is successful through the actionresult. succeed attribute </returns>
Public actionresult submitcostcode (costcode)
{
VaR rlt = new actionresult <costcode> (); // <1>
Using (var ctx = new basicdataentities ())
{
CTX. costcodes. applychanges (costcode );
RLT. succeed = CTX. savechanges ()> 0;
}
Return rlt;
}
Because the preceding <1> row accidentally declares the RLT variable as the actionresult <costcode> type rather than the actionresult type, no warning or error occurs during compilation, when the client calls the submitcostcode method, although the server can normally store data, it will throw a "Remote Server forced to close a connection" exception, which is confusing, it took two days to figure out the root cause of the problem (sweating here ...).
This is a special record, which warns future generations to urge themselves not to make similar mistakes in the future!