Answered by:
WCF Error Handling

Question
-
User-665281982 posted
I'm implementing error handling to WCF using IErrorHandler. By making the method ApplyDispatchBehavior, being appointed an error on the line:
channelDispatcher.ErrorHandlers.Add (new ErrorHandler (this));public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { foreach (ChannelDispatcherBase chanDispBase in serviceHostBase.ChannelDispatchers) { ChannelDispatcher channelDispatcher = chanDispBase as ChannelDispatcher; if (channelDispatcher == null) continue; channelDispatcher.ErrorHandlers.Add(new ErrorHandler(this)); } }
Error 1 The best overloaded method match for has some invalid arguments C: \ ServicesErrorHandling \ ErrorHandlingBehavior.cs 49 17Error 2 Argument 1: cannot convert from 'ServicesErrorHandling.ErrorHandler' to 'System.ServiceModel.Dispatcher.IErrorHandler' C:\ServicesErrorHandling\ErrorHandlingBehavior.cs 49 53
What can I do? checked in a solution with 3.5 framework and not of the problem.
Monday, June 3, 2013 9:13 AM
Answers
-
User220959680 posted
channelDispatcher.ErrorHandlers.Add(new ErrorHandler(this));
IErrorHandler.HandleError takes single parameter i.e., this.
Refer
// This behavior is an IErrorHandler implementation and // must be applied to each ChannelDispatcher. public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) { Console.WriteLine("The EnforceGreetingFaultBehavior has been applied."); foreach(ChannelDispatcher chanDisp in serviceHostBase.ChannelDispatchers) { chanDisp.ErrorHandlers.Add(this); } }
Note:- It is same for 3.5 or 4.0 or 4.5
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 3, 2013 9:55 AM
All replies
-
User220959680 posted
channelDispatcher.ErrorHandlers.Add(new ErrorHandler(this));
IErrorHandler.HandleError takes single parameter i.e., this.
Refer
// This behavior is an IErrorHandler implementation and // must be applied to each ChannelDispatcher. public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) { Console.WriteLine("The EnforceGreetingFaultBehavior has been applied."); foreach(ChannelDispatcher chanDisp in serviceHostBase.ChannelDispatchers) { chanDisp.ErrorHandlers.Add(this); } }
Note:- It is same for 3.5 or 4.0 or 4.5
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 3, 2013 9:55 AM -
User-665281982 posted
Still giving error:
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers) { dispatcher.ErrorHandlers.Add(this); } }
Error 5 The best overloaded method match for 'System.Collections.ObjectModel.Collection<System.ServiceModel.Dispatcher.IErrorHandler>.Add(System.ServiceModel.Dispatcher.IErrorHandler)' has some invalid arguments C:\ErrorHandling\ErrorHandlerExtension.cs 40 17 ErrorHandling
Error 6 Argument 1: cannot convert from 'ErrorHandling.IErrorHandler' to 'System.ServiceModel.Dispatcher.IErrorHandler' C:\ErrorHandling\ErrorHandlerExtension.cs 40 46 ErrorHandling
I dont undestand what might be causing this problem...Monday, June 3, 2013 3:04 PM