WCF Added Custom SoapHeader in ServiceAuthenticationManager will not apper in IDispatchMessageInspector class RRS feed

  • Question

  • Hi I add custom soap header in ServiceAuthenticationManager and      want to use other stages in WCF.In ServiceAuthenticationManager have  input parameter MEssage with ref keyword.I added my custom soap header.

    But When I want to check this custom soap header in MessageInspector that time I cant see my custom soap header?

    What I want ,I want to add some custom information in my authenticationmanager and use in MessageInspector?


      public class MyAuthenticationManager: ServiceAuthenticationManager

            public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate(ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri, ref Message message)


                var messageheader2 = MessageHeader.CreateHeader("myheader", "myheaderuri", "myvalue");

          return base.Authenticate(authPolicy, listenUri, ref message);

     public class MessageInspector
            : IDispatchMessageInspector
            public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)


                var  mycustomheader=  reply.Headers.GetHeader<stringt>("myheader", "myheaderuri");

    //This code take error because my header not seen message...?


    Thursday, December 28, 2017 10:42 AM

All replies

  • Hi Bilgehan,

    What is the code for “reply”? There is no definition for “reply” in AfterReceiveRequest.

    If you put a breakpoint on “return base.Authenticate(authPolicy, listenUri, ref message);”, will message contain “myheader” after “base.Authenticate”?

    Do you want to check “myheader” in request or reply? Will the “request” contain this header?

    It would be helpful if you could share us a simple project which could reproduce your issue.

    In addition, has issue below resolved? If it has, I would suggest you mark the helpful reply as answer to close it. If not, please feel free to keep following.


    Best Regards,

    Tao Zhou

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, December 29, 2017 2:14 AM
  • I change my code and I use ServiceAuthorizationManager and Add My CustomHeader to MessageProperties that time



    ı can access from MessageInspector

    OperationContext.Current.IncomingMessageProperties.Where(p => p.Key == "MyCustomHeader").FirstOrDefault();

    like that .

    Friday, January 5, 2018 6:09 AM
  • Hi Bilgehan,

    Thanks for sharing it.

    I would suggest you mark your own reply as answer, and then others who run into the same issue would find the solution easily.



    Help each other

    Friday, January 5, 2018 6:25 AM