ErrorProcessingHandler.cs 999 B

12345678910111213141516171819202122232425262728293031
  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. protected override bool ProcessRequest (MessageProcessingContext mrc)
  11. {
  12. Exception ex = mrc.ProcessingException;
  13. DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
  14. //invoke all user handlers
  15. ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;
  16. foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
  17. if (handler.HandleError (ex))
  18. break;
  19. FaultConverter fc = FaultConverter.GetDefaultFaultConverter (dispatchRuntime.ChannelDispatcher.MessageVersion);
  20. Message res = null;
  21. if (!fc.TryCreateFaultMessage (ex, out res))
  22. throw ex;
  23. mrc.ReplyMessage = res;
  24. mrc.Reply (true);
  25. return false;
  26. }
  27. }
  28. }