Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Services (http://www.velocityreviews.com/forums/f64-asp-net-web-services.html)
-   -   SoapExtension and header information (http://www.velocityreviews.com/forums/t784038-soapextension-and-header-information.html)

Ben 11-11-2004 07:46 PM

SoapExtension and header information
 
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****




[MSFT] 11-12-2004 02:32 AM

RE: SoapExtension and header information
 
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/de...us/cpguide/htm
l/cpconUsingSOAPHeaders.asp

Luke


Ben 11-12-2004 04:22 AM

Re: SoapExtension and header information
 
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]" <lukezhan@online.microsoft.com> wrote in message
news:bDoaP$FyEHA.768@cpmsftngxa10.phx.gbl...
> 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/de...us/cpguide/htm
> l/cpconUsingSOAPHeaders.asp
>
> Luke
>





[MSFT] 11-12-2004 07:08 AM

Re: SoapExtension and header information
 
Then you may take a look at this article, it has a sample about handling
SOAP Headers Using SoapExtensions:

http://msdn.microsoft.com/library/de...us/dnservice/h
tml/service06182002.asp

Hope this help!

Luke



Ben 11-13-2004 04:58 AM

Re: SoapExtension and header information
 
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 11-13-2004 05:13 AM

Re: SoapExtension and header information
 
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" <ben@online.nospam> wrote in message
news:fwgld.96$%Z.24@fe37.usenetserver.com...
>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;
>
> }
>
> }
>
> }
>
> }
>
>
>






All times are GMT. The time now is 05:15 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.