Dave
Dave

Reputation: 1950

Enterprise library exception handling problems with WCF services

my application consists of 3 layers and is very straightforward.

At the class library layer, I have an enterprise library exception handling policy defined so that it logs all exceptions to the database. In the underlying code, exceptions are thrown, and they coalesce up to the facade. In the facade, I trigger the EL policy to log the errors, and then I toggle a sucessStatus boolean in the response and have a method to convert all my exceptions to a friendly list so that the ultimate consumer can dig through this to get any idea of whats going on.

My facade in my class library sort of looks like this:

public SomeResponse DoSomething(SomeRequest request)
        {   
        SomeResponse response = new SomeResponse();
            try
            {
                response.data = SomeOperationThatWillThrowAnException;
            }
            catch (InvalidOperationException ex)
            {
                var exceptionManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
                exceptionManager.HandleException(ex, "StandardPolicy");
                response.Errors.Add(Utility.ExceptionToError(ex));
                response.SuccessStatus = false;
            }
        return response;
    }

If I build a simple winform client and have it talk to my class library, this works.

However when I use the full stack, I get "fault exception was unhandled by user code". I can't seem to configure EL at the WCF layer in any way to keep this from happening.

My WCF service is just a simple wrapper for my class library facade.

public SomeResponse DoSomething(SomeRequest request)
{
    return new MyFacade.DoSomething(request);
}

What I want is to have the class library handle the error silently, and not trigger any exceptions at the WCF or UI level. I want the consumer (in this case the ASP.NET webform UI) to have to check the response message contents to get a clue of what happened instead of having an exception stop execution dead in its tracks.

Upvotes: 0

Views: 433

Answers (1)

Tim B
Tim B

Reputation: 2368

You likely have an error in your configuration file resulting in GetInstance() or HandleException() throwing an exception. Have you tried debugging the WCF service?

Upvotes: 1

Related Questions