Click here to Skip to main content
15,895,084 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: ASMX: Facing problem to send user credentails from client side to service end Pin
jkirkerx19-Dec-16 11:40
professionaljkirkerx19-Dec-16 11:40 
GeneralRe: ASMX: Facing problem to send user credentails from client side to service end Pin
Tridip Bhattacharjee20-Dec-16 21:17
professionalTridip Bhattacharjee20-Dec-16 21:17 
AnswerRe: ASMX: Facing problem to send user credentails from client side to service end Pin
jkirkerx21-Dec-16 9:49
professionaljkirkerx21-Dec-16 9:49 
GeneralRe: ASMX: Facing problem to send user credentails from client side to service end Pin
Tridip Bhattacharjee21-Dec-16 20:31
professionalTridip Bhattacharjee21-Dec-16 20:31 
GeneralRe: ASMX: Facing problem to send user credentails from client side to service end Pin
jkirkerx22-Dec-16 8:20
professionaljkirkerx22-Dec-16 8:20 
GeneralRe: ASMX: Facing problem to send user credentails from client side to service end Pin
Tridip Bhattacharjee22-Dec-16 21:28
professionalTridip Bhattacharjee22-Dec-16 21:28 
GeneralRe: ASMX: Facing problem to send user credentails from client side to service end Pin
jkirkerx23-Dec-16 7:02
professionaljkirkerx23-Dec-16 7:02 
QuestionASMX Web Service Soap Extension ProcessMessage function not calling Pin
Tridip Bhattacharjee19-Dec-16 2:09
professionalTridip Bhattacharjee19-Dec-16 2:09 
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
C#
namespace EncryptASMX
{
    /// <summary>
    /// Summary description for Test1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 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;

        [AuthExtension]
        [SoapHeader("Credentials", Required = true)]
        [WebMethod]
        public string Add(int x, int y)
        {
            return (x + y).ToString();
        }
    }

    public class AuthenticateHeader : SoapHeader
    {
        public string UserName;
        public string Password;
    }

    [AttributeUsage(AttributeTargets.Method)]
    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
                //credentials
                foreach (SoapHeader header in message.Headers)
                {
                    if (header is AuthenticateHeader)
                    {
                        AuthenticateHeader credentials = (AuthenticateHeader)header;
                        if (credentials.UserName.ToLower() ==
                            "jeff" &&
                            credentials.Password.ToLower() ==
                            "imbatman")
                            return; // Allow call to execute
                        break;
                    }
                }

                // Fail the call if we get to here. Either the header
                // isn't there or it contains invalid credentials.
                throw new SoapException("Unauthorized",
                    SoapException.ClientFaultCode);
            }
        }

        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
<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />

      <webServices>
        <soapExtensionTypes>
          <add type="EncryptASMX.AuthExtension,EncryptASMX" priority="1"  />
        </soapExtensionTypes>
      </webServices>

    </system.web>

</configuration>


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

http://www.c-sharpcorner.com/article/using-soap-header-and-soap-extensions-in-a-web-service/

http://www.codeguru.com/csharp/csharp/cs_webservices/security/article.php/c5479/Build-Secure-Web-Services-With-SOAP-Headers-and-Extensions.htm
tbhattacharjee

AnswerRe: ASMX Web Service Soap Extension ProcessMessage function not calling Pin
Tridip Bhattacharjee21-Dec-16 20:32
professionalTridip Bhattacharjee21-Dec-16 20:32 
Questionasp .net web development Pin
Sanju govind18-Dec-16 20:53
Sanju govind18-Dec-16 20:53 
AnswerRe: asp .net web development Pin
Peter Leow18-Dec-16 21:02
professionalPeter Leow18-Dec-16 21:02 
QuestionRe: asp .net web development Pin
ZurdoDev19-Dec-16 8:23
professionalZurdoDev19-Dec-16 8:23 
AnswerRe: asp .net web development Pin
koolprasad200320-Dec-16 22:43
professionalkoolprasad200320-Dec-16 22:43 
QuestionNeed help on passing id to next page on response.redirect Pin
Bootzilla3318-Dec-16 10:43
Bootzilla3318-Dec-16 10:43 
AnswerRe: Need help on passing id to next page on response.redirect Pin
F-ES Sitecore18-Dec-16 21:59
professionalF-ES Sitecore18-Dec-16 21:59 
QuestionData not updating on fields using UPDATE Statement Pin
Bootzilla3318-Dec-16 10:41
Bootzilla3318-Dec-16 10:41 
AnswerRe: Data not updating on fields using UPDATE Statement Pin
Richard Deeming19-Dec-16 2:33
mveRichard Deeming19-Dec-16 2:33 
GeneralRe: Data not updating on fields using UPDATE Statement Pin
Bootzilla3319-Dec-16 8:21
Bootzilla3319-Dec-16 8:21 
AnswerRe: Data not updating on fields using UPDATE Statement Pin
ZurdoDev19-Dec-16 8:25
professionalZurdoDev19-Dec-16 8:25 
QuestionDropdown pre-filled from prior page fires off required validator Pin
Bootzilla3315-Dec-16 9:54
Bootzilla3315-Dec-16 9:54 
AnswerRe: Dropdown pre-filled from prior page fires off required validator Pin
Richard Deeming16-Dec-16 2:05
mveRichard Deeming16-Dec-16 2:05 
GeneralRe: Dropdown pre-filled from prior page fires off required validator Pin
Bootzilla3316-Dec-16 6:49
Bootzilla3316-Dec-16 6:49 
GeneralRe: Dropdown pre-filled from prior page fires off required validator Pin
Richard Deeming16-Dec-16 9:54
mveRichard Deeming16-Dec-16 9:54 
GeneralRe: Dropdown pre-filled from prior page fires off required validator Pin
Bootzilla3316-Dec-16 17:15
Bootzilla3316-Dec-16 17:15 
GeneralRe: Dropdown pre-filled from prior page fires off required validator Pin
Richard Deeming19-Dec-16 1:58
mveRichard Deeming19-Dec-16 1:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.