SoapExtension and header information

B

Ben

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****
 
B

Ben

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
 
B

Ben

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;

}

}

}

}
 
B

Ben

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 said:
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;

}

}

}

}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top