Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > SoapExtension and header information

Reply
Thread Tools

SoapExtension and header information

 
 
Ben
Guest
Posts: n/a
 
      11-11-2004
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****



 
Reply With Quote
 
 
 
 
[MSFT]
Guest
Posts: n/a
 
      11-12-2004
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

 
Reply With Quote
 
 
 
 
Ben
Guest
Posts: n/a
 
      11-12-2004
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]" <(E-Mail Removed)> wrote in message
news:bDoaP$(E-Mail Removed)...
> 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
>




 
Reply With Quote
 
[MSFT]
Guest
Posts: n/a
 
      11-12-2004
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


 
Reply With Quote
 
Ben
Guest
Posts: n/a
 
      11-13-2004
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;

}

}

}

}



 
Reply With Quote
 
Ben
Guest
Posts: n/a
 
      11-13-2004
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" <(E-Mail Removed)> wrote in message
news:fwgld.96$%(E-Mail Removed)...
>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;
>
> }
>
> }
>
> }
>
> }
>
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
How to Add dynamic header in SoapExtension gilad ASP .Net Web Services 0 03-19-2007 09:17 AM
SoapExtension and Web Service Validation Ted A W ASP .Net 0 01-12-2006 07:30 PM
Encrypting XML header via SoapExtension issues cordata5 ASP .Net Web Services 1 11-19-2004 07:20 PM
encryption and decryption using SoapExtension Henrik Bruhn ASP .Net Web Services 0 02-18-2004 11:55 AM



Advertisments