ErrorProcessingHandler.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ServiceModel.Channels;
  5. using System.ServiceModel;
  6. namespace System.ServiceModel.Dispatcher
  7. {
  8. internal class ErrorProcessingHandler : BaseRequestProcessorHandler
  9. {
  10. public ErrorProcessingHandler (IChannel channel)
  11. {
  12. duplex = channel as IDuplexChannel;
  13. }
  14. IDuplexChannel duplex;
  15. protected override bool ProcessRequest (MessageProcessingContext mrc)
  16. {
  17. Exception ex = mrc.ProcessingException;
  18. DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
  19. //invoke all user handlers
  20. ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;
  21. foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
  22. if (handler.HandleError (ex))
  23. break;
  24. // FIXME: remove them. FaultConverter also covers errors like EndpointNotFoundException, which this handler never covers. And checking converter twice is extraneous, so this part is just extraneous.
  25. // FIXME: instead, FaultContractInfos should be checked
  26. FaultConverter fc = FaultConverter.GetDefaultFaultConverter (dispatchRuntime.ChannelDispatcher.MessageVersion);
  27. Message res = null;
  28. if (!fc.TryCreateFaultMessage (ex, out res))
  29. throw ex;
  30. mrc.ReplyMessage = res;
  31. if (duplex != null)
  32. mrc.Reply (duplex, true);
  33. else
  34. mrc.Reply (true);
  35. return false;
  36. }
  37. }
  38. }