简体   繁体   中英

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"}

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.

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")...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM