Click here to Skip to main content
13,298,551 members (62,359 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 27 Jan 2014

OneTrueError and the WCF Integration

, 4 Aug 2014
Rate this:
Please Sign up or sign in to vote.
OneTrueError and the WCF Integration

OneTrueError has a complete WCF integration following the same pattern as WCF. It makes it a breeze to capture and analyze errors in WCF applications.


First of all, you need to have an account at

Start by installing the onetrueerror.wcf package. Then create a class with a <c>AppInitialize() method. AppInitialize is the recommended way to initialize code in WCF applications. The class must be put in a folder named App_Code.

public class InitializeService
    public static void AppInitialize()
        OneTrue.Configuration.Credentials("YourAppKey", "yourSharedSecret");

That’s all you need to activate OneTrueError for automatic error handling. If you don’t get any reports uploaded to your account, you can configure the library error handler as shown in this example.

Library Activation

The above configuration will inject OneTrueError into the WCF pipeline, but you still need to tell OneTrueError which services you want to get automatic error handling for.

You can either do that by decorating your service class with our attribute:

public class OrderService : IOrderService
    // [...]

... or by activating it through the configuration file:

      <!-- the new behavior -->
      <add name="OneTrueErrorHandler" 

       type="OneTrueError.Reporting.WCF.OneTrueErrorBehavior, OneTrueError.Reporting.WCF" />
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>

        <!-- and the activation -->
        <OneTrueErrorHandler />

The end result is that our error identification is now attached to the response from WCF:


By visiting the included link, the user can track the error and leave feedback to you. You can also see the number of users which are tracking each incident (unique error) in your system.

We also honer the includeExceptionDetailInFaults configuration element. If you include it, we’ll attach exception information to the returned SOAP fault.

We do however have another configuration option: to include just the exception message (to give the user a hint about what went strong). To activate it, leave includeExceptionDetailInFaults to false and change the service attribute:

[OneTrueErrorHandler(IncludeExceptionMessage = true)]
public class OrderService : IOrderService

That’s pretty much the basics.


You might want to customize the error message or the fault message which is generated. That can be achieved by assigning your own factories to the library.

Custom Error Message

public class InitialiseService
    public static void AppInitialize()
        OneTrue.Configuration.Credentials("YourAppKey", "yourSharedSecret");

        //assign the own factory
        OneTrue.Configuration.SetErrorMessageFactory(new CustomFaultMessageFactory());


public class CustomFaultMessageFactory : IErrorMessageFactory
    public string Create(WcfErrorReporterContext context, string reportId)
        var message = string.Format(@"You failed this application! 
        You still have one chance left. 
        Visit{0}/ and make amends.", reportId);

        if (context.IncludeExceptionDetailInFaults)
            message += "\r\n\r\nError details: " + context.Exception;
        else if (context.IncludeExceptionMessageInFaults)
            message += "\r\n\r\nError reason: " + context.Exception.Message;

        return message;

The result:


Fault Customization

SOAP errors are transferred as something which is called faults. These faults are basically wrapping the thrown exception to enable transport.

With OneTrueError, you can customize the returned error by doing as follows:

public class InitializeService
    public static void AppInitialize()
        OneTrue.Configuration.Credentials("YourAppKey", "yourSharedSecret");

And create your custom implementation of:

public interface IFaultMessageFactory
    Message Create(WcfErrorReporterContext context, MessageVersion version, string errorMessage);

The return value is a standard WCF message class.



All examples are available in our github account.


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


About the Author

Founder 1TCompany AB
Sweden Sweden
Skip logfiles, try automated error handling!

I'm one of the founders of codeRR, a .NET service which takes care of everything related to exceptions, so that you can focus on writing code.

blog | twitter

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 4 Aug 2014
Article Copyright 2014 by jgauffin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid