Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:37:13+00:00 2026-06-05T17:37:13+00:00

I am using a WCF Service and I have implemented IErrorHandler . In the

  • 0

I am using a WCF Service and I have implemented IErrorHandler. In the HandleError method, I want to retrieve the caller’s username in order to set a ThreadContext property for Log4Net (to save the username along with the exception details in SQL Server)

My code is working well if I avoid trying to retrieve the caller’s username.

This is the line of code inside the HandleError method which is returning a NullReferenceException:

string username = ServiceSecurityContext.Current.WindowsIdentity.Name;

It seems that at the point the HandleError method of IErrorHandler kicks in, the original caller information has been disposed.

Does anyone have any idea how I can retrieve the caller’s username inside the HandlerError method of IErrorHandler?

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:37:15+00:00Added an answer on June 5, 2026 at 5:37 pm

    Thanks to those who responded to help. My security appears to be configured correctly but I cannot retrieve the username in the HandleError method of the IErrorHandler interface in the WCF service. However, I am able to retrieve the username in the ProvideFault method. So, I declared a class level variable in the ErrorHandler (IErrorHandler) class which is set during the ProvideFault method and then read and logged with the exception in the ErrorHandler method. This is a “workaround” and not my preference, but unfortunately I cannot seem to access the security context inside the HandleError method.

    Here is a sample of the code:

    public class ErrorHandler : IErrorHandler, IServiceBehavior
    {
        private string username = null;
    
        public bool HandleError(Exception error)
        {
            //Log the exception along with the username.
            //...logging call including the username class member string...
    
            //Return true to indicate we have performed our behaviour.
            return true;
        }
    
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
                //Retrieve the username.
                username = ServiceSecurityContext.Current.WindowsIdentity.Name;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF Service Library (implemented using NH) with one of the class
I have successfully implemented a standard WCF service bound to MSMQ using the net.msmq
Here is my question I have a WCF service that I implemented using a
I have a WCF service implemented using the WebServiceHostFactory (REST). I'm calling a service
I have a WCF service client implemented using the asynchronous event (using /async and
I have a WCF RESTful web service , I have implemented cache mechanism using
I have developed a Web service using WCF Service Application. This service application is
I have a Data Service created using WCF that internally uses nHibernate. This WCF
I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I am designing a WCF service using DDD. I have a domain service layer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.