Corith Malin
Corith Malin

Reputation: 1525

WCF Unit Testing Results in a System.ServiceModel.FaultException

So I have a WCF service that seems to work perfectly in a deployed production environment. My build intermittently fails though during the unit testing of this WCF service. The weird part is that it's not always the same unit test, but it is always a unit test which uses the WCF service.

Exception:

System.ServiceModel.FaultException[System.ServiceModel.ExceptionDetail]: The number of bytes available is inconsistent with the HTTP Content-Length header.  There may have been a network error or the client may be sending invalid requests.

The weird part is that the exception really only happens on the build machine and never on a developer machine. And it seems to only happen about 75% of the time.

WCF isn't my strongest aspect of .NET so any help pointing me in the correct direction would be useful.

Upvotes: 2

Views: 1919

Answers (1)

Corith Malin
Corith Malin

Reputation: 1525

This issue ended up being that inside a catch clause we had:

var proxy = new WcfProxy();

try
{
  // Do something.
}
catch (Exception ex)
{
  proxy.Close();
  throw;
}

Where the catch clause should have used proxy.Abort() as Close() can throw another exception.

catch (Exception ex)
{
  proxy.Abort();
  throw;
}

Upvotes: 1

Related Questions