title: How to pass a SOAP header from a client to a web service
body: <p>I have a client in C# and the Web Service must receive a certificate header. I don't know how to add the header to the Web Service. This is my code:</p>
  
  <pre><code>// Define a SOAP header by deriving from the SoapHeader base class.
  // The header contains just one string value.
  public class MyHeader : SoapHeader
  {
      public string MyValue;
  }
  
  public partial class Service: System.Web.UI.Page
  {
      MyWebService ESClient = new MyWebservice();
      private static String TAG_CERTIFICATE = "MxIFZjFCBFa...";
      protected void Page_Load(object sender, EventArgs e)
      {
          ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
          CredentialCache cache = new CredentialCache();
  
          MyHeader header = new MyHeader();
  
          // Populate the values of the SOAP header.
          header.MyValue = TAG_CERTIFICATE;
  
          //HOW CAN I ADD THIS CERTIFICATE TO MY ESCLIENT WEB SERVICE?????
  
          //remSolSal is the response of the Web Service
          remSolSal response= new remSolSal();
          //remDatSol is the method of the Web Service and getRemSolEnt the parameters that I send in another function
          response = ESClient.remDatSol(getRemSolEnt());
      }
  </code></pre>
  
  <p>The XML model certificate:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sol="url..."&gt;
      &lt;soapenv:Header&gt;
          &lt;certificate&gt;
              JgsJSP6Ql8f........
          &lt;/certificate&gt;
  </code></pre>
  
  <p>Also, I have a client in Java that makes what I have to do in C#. It uses a this funtion to add the header, where paramName is "certificate" and paramContent is the value "JgsJSP6Ql8f........":</p>
  
  <pre><code> /**
   * This method adds a custom header to message.
   * 
   * @param paramName
   */
  private static void addHeaderParam(String paramName, String paramContent) {
      try {
          List&lt;Header&gt; headers = new ArrayList&lt;Header&gt;();
          Header dummyHeader = new Header(new QName(TARGETNAMESPACE,
                  paramName), paramContent, new JAXBDataBinding(String.class));
          headers.add(dummyHeader);
  
          // client side:
          ((BindingProvider) port).getRequestContext().put(
                  Header.HEADER_LIST, headers);
      } catch (JAXBException e) {
          e.printStackTrace();
      }
  }
  </code></pre>