Rakesh
Rakesh

Reputation: 73

How to access the SOAP HEADER in C#

How to access the SOAP header into a class. Scenario: SOAP request is sent form client to web-service.

[SoapHeader("transactionInfo", Direction = SoapHeaderDirection.In)]
public byte[] method1(DocumentInfo templateInfo,System.Xml.XmlDocument xml,string Name)
{"code to get the tags in soap header"}

Upvotes: 0

Views: 4272

Answers (2)

Emanuele Greco
Emanuele Greco

Reputation: 12721

1 - Define your custom SoapHeader

  public class transactionInfo: System.Web.Services.Protocols.SoapHeader
  {
    public string  Info;
  }

2 - Define you header inside your web service

[WebService(Namespace = "http://..")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 public class MyWebService : System.Web.Services.WebService
{
    public transactionInfo Header  { get; set; }
    ...

3 - Define, inside your web service, a method that uses this SoapHeader

  [SoapHeader("transactionInfo", Direction = SoapHeaderDirection.InOut)]
    public void MyMethod()
    {
    }

[this is the answer to your question]
4 - Access the value of the header from the metod MyMethod using the property

  if (Header.Info == "none")...

Upvotes: 0

John Saunders
John Saunders

Reputation: 161773

If your code is working properly, you will find that you have a field named transactionInfo defined in your WebService class. That field will contain the SOAP Header, in a deserialized form.

I have never done this, but I suspect that if the transactionInfo field is of type XmlElement, then you will be able to access it as XML. Otherwise, you will be able to access it as a C# object.

Upvotes: 1

Related Questions