2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / ErrorProcessingHandler.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.ServiceModel.Channels;
5 using System.ServiceModel;
6
7 namespace System.ServiceModel.Dispatcher
8 {
9         internal class ErrorProcessingHandler : BaseRequestProcessorHandler
10         {
11                 public ErrorProcessingHandler (IChannel channel)
12                 {
13                         duplex = channel as IDuplexChannel;
14                 }
15
16                 IDuplexChannel duplex;
17
18                 protected override bool ProcessRequest (MessageProcessingContext mrc)
19                 {
20                         Exception ex = mrc.ProcessingException;
21                         DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
22                         
23                         //invoke all user handlers
24                         ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;
25                         foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
26                                 if (handler.HandleError (ex))
27                                         break;
28
29                         FaultConverter fc = FaultConverter.GetDefaultFaultConverter (dispatchRuntime.ChannelDispatcher.MessageVersion);
30                         Message res = null;                     
31                         if (!fc.TryCreateFaultMessage (ex, out res))
32                                 throw ex;
33                         mrc.ReplyMessage = res;
34                         if (duplex != null)
35                                 mrc.Reply (duplex, true);
36                         else
37                                 mrc.Reply (true);
38                         return false;
39                 }               
40         }
41 }