ASMX Web Service Soap Extension ProcessMessage function not calling RRS feed

  • Question

  • i have a asmx web service and i attached the Soap Extension just to intercept data and encrypt/decrypt it but the problem is Soap Extension ProcessMessage function not calling

    here is my full code with web.config and i am running the code from VS2013.

    please see my code and tell me where i made the mistake for which ProcessMessage function not calling

    namespace EncryptASMX
        /// <summary>
        /// Summary description for Test1
        /// </summary>
        [WebService(Namespace = "")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class Test1 : System.Web.Services.WebService
            public AuthenticateHeader Credentials;
            [SoapHeader("Credentials", Required = true)]
            public string Add(int x, int y)
                return (x + y).ToString();
        public class AuthenticateHeader : SoapHeader
            public string UserName;
            public string Password;
        public class AuthExtensionAttribute : SoapExtensionAttribute
            int _priority = 1;
            public override int Priority
                get { return _priority; }
                set { _priority = value; }
            public override Type ExtensionType
                get { return typeof(AuthExtension); }
        public class AuthExtension : SoapExtension
            public override void ProcessMessage(SoapMessage message)
                if (message.Stage == SoapMessageStage.AfterDeserialize)
                    //Check for an AuthHeader containing valid
                    foreach (SoapHeader header in message.Headers)
                        if (header is AuthenticateHeader)
                            AuthenticateHeader credentials = (AuthenticateHeader)header;
                            if (credentials.UserName.ToLower() ==
                                "jeff" &&
                                credentials.Password.ToLower() ==
                                return; // Allow call to execute
                    // Fail the call if we get to here. Either the header
                    // isn't there or it contains invalid credentials.
                    throw new SoapException("Unauthorized",
            public override Object GetInitializer(Type type)
                return GetType();
            public override Object GetInitializer(LogicalMethodInfo info,
                SoapExtensionAttribute attribute)
                return null;
            public override void Initialize(Object initializer)

    web.config entry

    <?xml version="1.0"?>
      For more information on how to configure your ASP.NET application, please visit
          <compilation debug="true" targetFramework="4.5" />
          <httpRuntime targetFramework="4.5" />
              <add type="EncryptASMX.AuthExtension,EncryptASMX" priority="1"  />

    i consult two links but still not configure how to run process message. here are the links

    • Edited by Sudip_inn Monday, December 19, 2016 1:06 PM
    Monday, December 19, 2016 1:04 PM


  • Hi Mou_inn,

    How did you call Add method? Did you invoke the Add function in Web Browser or create a client? In my option, SOAP extensions are between a Web Service and Web Service client.

    For consuming SOAP Extension, I suggest you create a Web Service Client by Add Service Reference in VS->Advanced->Add Web Reference->Enter the Web Service URL and Add Reference. After you call Add method from Web Service Client, you will find the ProcessMessage is called.

    Best Regards,


    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

    • Marked as answer by Sudip_inn Wednesday, December 21, 2016 1:25 PM
    Tuesday, December 20, 2016 2:42 AM