0

I have an simple WCF server where I am throwing FaultException<InvalidOperationException> but on client side i only get the Communication exception with error below.

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.8080000'.

See below for code I am having, please help and let me know if something is missing.

Service

[OperationContract]
[FaultContract(typeof(InvalidOperationException))]
bool DoWork()

Service implementation code

public bool DoWork()
    {var invalidOperationException =
          new InvalidOperationException(
            "Can't dowork", exception);

        // throw InvalidOperationException as an FaultException to the service consumer.
        throw new FaultException<InvalidOperationException>(
          invalidOperationException,
             exception.Message,
              new FaultCode("Test Message"),
              "DoWork");
}

Client side code.

try
{
 var service = new ServiceClient();
 var result = service.DoWork();
}
catch (TimeoutException timeoutException)
          {

          }
          catch (FaultException<InvalidOperationException> invalidOperationException)
          {

          }
          catch (FaultException unknownFault)
          {

          }
          catch (CommunicationException communicationException)
          {

          }
Keshavdas M
  • 674
  • 2
  • 7
  • 25

1 Answers1

2

The problem is the inner exception provided in

var invalidOperationException =
      new InvalidOperationException(
        "Can't dowork", exception);

If you remove that it will work.

My guess is that It has something to do with trying to serialize an CLR exception.

Jon Lindeheim
  • 582
  • 4
  • 10
  • Thanks I already removed inner exception and it is working fine. I was about to respond and saw your answer exactly saying the same. Any way thank you so much for the response. – Keshavdas M May 14 '14 at 08:29