WCF error: the underlying connection was closed an unexpected error occurred on a receive

I don’t like to post solution as comment industry, strategies, patterns… But this solution gave me happiness. I want to share it because these error has so many reasons to happen I haven’t found solution anywhere.

I had the folowing problem:

System.Exception: An error occurred while receiving the HTTP response to http://soaAdress.com. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details..

which datails:

the underlying connection was closed an unexpected error occurred on a receive

I thought my client application was fine because it closes the connection. Last time I had problem with WCF calls, the calls stopped at 11º one because we can’t keep a stabilished connection to perform more than 10 calls. But this time I couldn’t close. The service contract has 4 operations:

[OperationContract(IsOneWay = false)]
myEntity GetComission(long id);

[OperationContract(IsOneWay = false)]
myEntity GetComissionPartial(long id);

[OperationContract(IsOneWay = false)]
myEntity GetComissionAuto(long id);

[OperationContract(IsOneWay = true)]
void CloseOderProcess(Contracts.CloseMessageOrder input);

The dump file was terrible to read, but I found something:

“The message could not be processed. This is most likely because the action
http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT/Cancel’ is incorrect or
because the message contains an invalid or expired security context token or
because there is a mismatch between bindings. The security context token
would be invalid
if the service aborted the channel due to inactivity. To
prevent the service from aborting idle sessions prematurely increase the
Receive timeout on the service endpoint’s binding.”

It let me to a conclusion, if the service operation is IsOneWay = true, I shouldn’t close it. The service wouldn’t have the security token anymore as there is a very short connection between service and consumer and the message is operated asynchronously as stated in the contract. So I removed the .close operation and things are working now.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: