The WCF Remote Server forces a connection to be closed.

Source: Internet
Author: User
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!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.