I am trying to implement IErrorHandler in the WCF services that uses iis and net.tcp.
I set a scenario to throw DivideByZeroException in the server. IErrorHandler is firing as expected.
The FaultException is not returning to client and I am getting timeout exception. I could not find any info/exception in event log also.
Here is the demo code. http://www.fileswap.com/dl/gQFlVsZK7M/ (Please click on slow download image)
EDIT 1 (added code from archive for all to see it):
Service contract:
[ServiceContract]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
string GetData(int value);
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
Service Implementation:
public class Service1 : IService1
{
public string GetData(int value)
{
int i = 0;
//division by zero!
int y = 10/i;
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
IErrorHandler implementation:
public class WcfErrorHandler : IErrorHandler
{
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
var v = error as DivideByZeroException;
if (v != null)
fault = Message.CreateMessage(
version,
new FaultException<DivideByZeroException>(v, new FaultReason(v.Message)).CreateMessageFault(),
"http://the.fault.action");
}
public bool HandleError(Exception error)
{
return true;
}
}