Пример #1
0
    public override void ProcessMessage(SoapMessage message)
    {
        if (message.Stage == SoapMessageStage.AfterDeserialize)
        {
            foreach (SoapHeader header in message.Headers)
            {
                if (header is ServiceAuthHeader)
                {
                    authHeader = (ServiceAuthHeader)header;

                    if (authHeader.Password == TheCorrectUserPassword)
                    {
                        return;      //confirmed
                    }
                }
            }

            throw new SoapException("Unauthorized", SoapException.ClientFaultCode);
        }
    }
Пример #2
0
            public static bool Validate(ServiceAuthHeader soapHeader)
            {
                if (soapHeader == null)
                {
                    throw new NullReferenceException("No soap header was specified.");
                }
                if (soapHeader.Username == null)
                {
                    throw new NullReferenceException("Username was not supplied for authentication in SoapHeader.");
                }
                if (soapHeader.Password == null)
                {
                    throw new NullReferenceException("Password was not supplied for authentication in SoapHeader.");
                }

                string UserName = System.Configuration.ConfigurationManager.AppSettings["UserName"];
                string PassWord = System.Configuration.ConfigurationManager.AppSettings["PassWord"];

                if (soapHeader.Username != UserName || soapHeader.Password != PassWord)
                {
                    throw new Exception("Please pass the proper username and password for this service.");
                }
                return(true);
            }