2010-04-02 Atsushi Enomoto <atsushi@ximian.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                         // 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.
30                         // FIXME: instead, FaultContractInfos should be checked
31                         FaultConverter fc = FaultConverter.GetDefaultFaultConverter (dispatchRuntime.ChannelDispatcher.MessageVersion);
32                         Message res = null;                     
33                         if (!fc.TryCreateFaultMessage (ex, out res))
34                                 throw ex;
35                         mrc.ReplyMessage = res;
36
37                         if (duplex != null)
38                                 mrc.Reply (duplex, true);
39                         else
40                                 mrc.Reply (true);
41                         return false;
42                 }               
43         }
44 }