Skip to content

SoapHeaderAttribute: How to use a header parameter in ASP.Net web method

January 17, 2007

The most common way to pass parameters to a web method is through the SOAP body. However, sometimes you may want to pass parameters to web methods in the header. A common example for this is perhaps a “session” id or some other value used to create a stateful interface (like SSRS web services).

Here’s what you need to do (taken from MSDN)

  1. Create a class deriving from SoapHeader representing the data passed in the SOAP header.
  2. Add a member to the XML Web service class or XML Web service client proxy class of the type created in step 1.
  3. Apply a SoapHeaderAttribute to the XML Web service method or the corresponding method in the proxy class, specifying the member created in step 2 in the MemberName property.
  4. Within the XML Web service method or XML Web service client code, access the MemberName property to process the data sent in the SOAP header.

 For example, in a web service I created that augments the SSRS web service:

Declared a property of type ExecutionHeader:
public ExecutionHeader ExecutionHeaderValue = new ExecutionHeader();
Apple the SoapHeaderAttribute to my web method:

[SoapHeaderAttribute(“ExecutionHeaderValue”, Direction=SoapHeaderDirection.InOut)]

In the method I use the property value as usual:
if(ExecutionHeaderValue.ExecutionID == null || ExecutionHeaderValue.ExecutionID == “null”)


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: