SoapExtension and header information

Discussion in 'ASP .Net Web Services' started by Ben, Nov 11, 2004.

  1. Ben

    Ben Guest

    I appologize for the crosspost to microsoft.public.webservices, I didn't
    intend to post there at all.

    I'm new to Soap and I'm trying to write a SoapExtension that will perform
    authentication.

    I have the code below and I can't seem to access the information in the
    header. I've tried putting the header attribute on the soap extension,
    looking at the message.Headers (its there I can see it in the debugger),
    taking the message.Stream and loading it into an xml DOM, nothing is
    working... In the web method I can successfully access the GUID. Which I
    can't seem to access in the extension?

    Please any advice on how I can access the GUID in the header from my code?
    ****Extenstion****
    public class SecurityHeader : SoapHeader
    {
    public System.Guid UserGuid;
    }

    public class SecurityExtension : SoapExtension
    {
    public override void ProcessMessage(SoapMessage message)
    {
    switch (message.Stage)
    {
    // stage doesn't seem to affect the availablility of header
    reachability
    }
    }
    }

    [AttributeUsage(AttributeTargets.Method)]
    public class SecurityExtensionAttribute : SoapExtensionAttribute
    {
    public override Type ExtensionType
    {
    get
    {
    return typeof(SecurityExtension);
    }
    }
    }
    ****Extenstion****

    ****Web Method****
    [WebMethod(Description="Hello World")]
    [SoapHeader("_SecurityHeader")]
    [SecurityExtensionAttribute]
    public string HelloWorld()
    {
    HttpContext.Current.Trace.Warn("WebMethod",
    _Security.UserGuid.ToString());
    return "Hello World";
    }
    ****Web Method****
     
    Ben, Nov 11, 2004
    #1
    1. Advertising

  2. Ben

    [MSFT] Guest

    Hello Ben,

    To use the SoapHeader for a web method, we need declare a variant in the
    web service class with the header anme, for example:

    public SecurityHeader _SecurityHeader;

    And specify the SoapHeader attribute as:

    [SoapHeader("_SecurityHeaderr", Direction=SoapHeaderDirection.Out,
    Required=true)]

    For more detail for Soap Header, you may refer to:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
    l/cpconUsingSOAPHeaders.asp

    Luke
     
    [MSFT], Nov 12, 2004
    #2
    1. Advertising

  3. Ben

    Ben Guest

    I don't have a problem accessing the soap header inside the web method, its
    the web extension that can't access the header. I have the line of code you
    suggest in place inside the asmx.cs.

    It boils down to me wanting to read a header inside the process message of a
    web extension. The header value IS available in the web method, the problem
    is I can't seem to access it in the soap extension.

    Thanks,
    Ben

    "[MSFT]" <> wrote in message
    news:bDoaP$...
    > Hello Ben,
    >
    > To use the SoapHeader for a web method, we need declare a variant in the
    > web service class with the header anme, for example:
    >
    > public SecurityHeader _SecurityHeader;
    >
    > And specify the SoapHeader attribute as:
    >
    > [SoapHeader("_SecurityHeaderr", Direction=SoapHeaderDirection.Out,
    > Required=true)]
    >
    > For more detail for Soap Header, you may refer to:
    >
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
    > l/cpconUsingSOAPHeaders.asp
    >
    > Luke
    >
     
    Ben, Nov 12, 2004
    #3
  4. Ben

    [MSFT] Guest

    [MSFT], Nov 12, 2004
    #4
  5. Ben

    Ben Guest

    I don't see anything at that link relating soap extenstions to soap headers.
    Perhaps I'm not using the correct terminology. Below is all of my code.

    What I'm trying to accomplish is inside the SecurityExtension class method
    ProcessMessage access the SecurityHeader. Now, inside the LinkService
    HelloWorld method I have no problem accessing the SecurityHeader
    information.

    Thanks,
    Ben

    The web service:
    *****************************************************
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;

    namespace LinkService
    {
    public class Links : System.Web.Services.WebService
    {
    public SecurityHeader SecurityInfo;

    public Links()
    {
    //CODEGEN: This call is required by the ASP.NET Web Services Designer
    InitializeComponent();
    }

    #region Component Designer generated code

    //Required by the Web Services Designer
    private IContainer components = null;

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if(disposing && components != null)
    {
    components.Dispose();
    }
    base.Dispose(disposing);
    }

    #endregion

    [WebMethod(Description="Hello World")]
    [SoapHeader("SecurityInfo")]
    [SecurityExtensionAttribute]
    public string HelloWorld()
    {
    return "Hello World";
    }
    }
    }
    **********************************************
    The security extenstion:
    **********************************************
    using System;

    using System.Web;

    using System.Web.Services.Protocols;

    namespace LinkService

    {

    public class SecurityHeader : SoapHeader

    {

    public Guid UserGuid;

    }

    public class SecurityExtension : SoapExtension

    {

    public SecurityHeader SecurityInfo;

    public override object GetInitializer(Type serviceType)

    {

    return null;

    }

    public override System.IO.Stream ChainStream(System.IO.Stream stream)

    {

    return base.ChainStream (stream);

    }

    public override object GetInitializer(LogicalMethodInfo methodInfo,
    SoapExtensionAttribute attribute)

    {

    return null;

    }

    public override void Initialize(object initializer)

    {


    }

    [SoapHeader("SecurityInfo")]

    public override void ProcessMessage(SoapMessage message)

    {

    if (SecurityInfo != null)

    {

    HttpContext.Current.Trace.Warn("ProcessMessage",
    SecurityInfo.UserGuid.ToString());

    }

    HttpContext.Current.Trace.Warn("In It", "doh");

    switch (message.Stage)

    {

    case SoapMessageStage.BeforeDeserialize:

    break;

    case SoapMessageStage.AfterDeserialize:

    break;

    case SoapMessageStage.BeforeSerialize:

    break;

    case SoapMessageStage.AfterSerialize:

    break;

    }

    }

    }

    [AttributeUsage(AttributeTargets.All)]

    public class SecurityExtensionAttribute : SoapExtensionAttribute

    {

    private int _Priority;

    public override Type ExtensionType

    {

    get

    {

    return typeof(SecurityExtension);

    }

    }

    public override int Priority

    {

    get

    {

    return _Priority;

    }

    set

    {

    _Priority = value;

    }

    }

    public override object TypeId

    {

    get

    {

    return base.TypeId;

    }

    }

    }

    }
     
    Ben, Nov 13, 2004
    #5
  6. Ben

    Ben Guest

    Oops, I copied the link incorrectly. I see the article now. I'm digesting
    it now, if I have any problems I'll post a followup.

    "Ben" <> wrote in message
    news:fwgld.96$%...
    >I don't see anything at that link relating soap extenstions to soap
    >headers. Perhaps I'm not using the correct terminology. Below is all of my
    >code.
    >
    > What I'm trying to accomplish is inside the SecurityExtension class method
    > ProcessMessage access the SecurityHeader. Now, inside the LinkService
    > HelloWorld method I have no problem accessing the SecurityHeader
    > information.
    >
    > Thanks,
    > Ben
    >
    > The web service:
    > *****************************************************
    > using System;
    > using System.Collections;
    > using System.ComponentModel;
    > using System.Data;
    > using System.Diagnostics;
    > using System.Web;
    > using System.Web.Services;
    > using System.Web.Services.Protocols;
    >
    > namespace LinkService
    > {
    > public class Links : System.Web.Services.WebService
    > {
    > public SecurityHeader SecurityInfo;
    >
    > public Links()
    > {
    > //CODEGEN: This call is required by the ASP.NET Web Services Designer
    > InitializeComponent();
    > }
    >
    > #region Component Designer generated code
    >
    > //Required by the Web Services Designer
    > private IContainer components = null;
    >
    > /// <summary>
    > /// Required method for Designer support - do not modify
    > /// the contents of this method with the code editor.
    > /// </summary>
    > private void InitializeComponent()
    > {
    > }
    >
    > /// <summary>
    > /// Clean up any resources being used.
    > /// </summary>
    > protected override void Dispose( bool disposing )
    > {
    > if(disposing && components != null)
    > {
    > components.Dispose();
    > }
    > base.Dispose(disposing);
    > }
    >
    > #endregion
    >
    > [WebMethod(Description="Hello World")]
    > [SoapHeader("SecurityInfo")]
    > [SecurityExtensionAttribute]
    > public string HelloWorld()
    > {
    > return "Hello World";
    > }
    > }
    > }
    > **********************************************
    > The security extenstion:
    > **********************************************
    > using System;
    >
    > using System.Web;
    >
    > using System.Web.Services.Protocols;
    >
    > namespace LinkService
    >
    > {
    >
    > public class SecurityHeader : SoapHeader
    >
    > {
    >
    > public Guid UserGuid;
    >
    > }
    >
    > public class SecurityExtension : SoapExtension
    >
    > {
    >
    > public SecurityHeader SecurityInfo;
    >
    > public override object GetInitializer(Type serviceType)
    >
    > {
    >
    > return null;
    >
    > }
    >
    > public override System.IO.Stream ChainStream(System.IO.Stream stream)
    >
    > {
    >
    > return base.ChainStream (stream);
    >
    > }
    >
    > public override object GetInitializer(LogicalMethodInfo methodInfo,
    > SoapExtensionAttribute attribute)
    >
    > {
    >
    > return null;
    >
    > }
    >
    > public override void Initialize(object initializer)
    >
    > {
    >
    >
    > }
    >
    > [SoapHeader("SecurityInfo")]
    >
    > public override void ProcessMessage(SoapMessage message)
    >
    > {
    >
    > if (SecurityInfo != null)
    >
    > {
    >
    > HttpContext.Current.Trace.Warn("ProcessMessage",
    > SecurityInfo.UserGuid.ToString());
    >
    > }
    >
    > HttpContext.Current.Trace.Warn("In It", "doh");
    >
    > switch (message.Stage)
    >
    > {
    >
    > case SoapMessageStage.BeforeDeserialize:
    >
    > break;
    >
    > case SoapMessageStage.AfterDeserialize:
    >
    > break;
    >
    > case SoapMessageStage.BeforeSerialize:
    >
    > break;
    >
    > case SoapMessageStage.AfterSerialize:
    >
    > break;
    >
    > }
    >
    > }
    >
    > }
    >
    > [AttributeUsage(AttributeTargets.All)]
    >
    > public class SecurityExtensionAttribute : SoapExtensionAttribute
    >
    > {
    >
    > private int _Priority;
    >
    > public override Type ExtensionType
    >
    > {
    >
    > get
    >
    > {
    >
    > return typeof(SecurityExtension);
    >
    > }
    >
    > }
    >
    > public override int Priority
    >
    > {
    >
    > get
    >
    > {
    >
    > return _Priority;
    >
    > }
    >
    > set
    >
    > {
    >
    > _Priority = value;
    >
    > }
    >
    > }
    >
    > public override object TypeId
    >
    > {
    >
    > get
    >
    > {
    >
    > return base.TypeId;
    >
    > }
    >
    > }
    >
    > }
    >
    > }
    >
    >
    >
     
    Ben, Nov 13, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted A W
    Replies:
    0
    Views:
    381
    Ted A W
    Jan 12, 2006
  2. mlt
    Replies:
    2
    Views:
    907
    Jean-Marc Bourguet
    Jan 31, 2009
  3. Henrik Bruhn

    encryption and decryption using SoapExtension

    Henrik Bruhn, Feb 18, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    162
    Henrik Bruhn
    Feb 18, 2004
  4. cordata5

    Encrypting XML header via SoapExtension issues

    cordata5, Nov 19, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    174
    Dan Rogers
    Nov 19, 2004
  5. gilad

    How to Add dynamic header in SoapExtension

    gilad, Mar 19, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    250
    gilad
    Mar 19, 2007
Loading...

Share This Page