title: WCF Client Soap Security Header - UsernameToken & BinarySecurityToken Empty
body: <p>I'm trying to create a Soap request with security header like this :</p>
  
  <pre><code>&lt;soapenv:Header&gt;
    &lt;wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
      &lt;wsse:UsernameToken&gt;
        &lt;wsse:Username&gt;SomeUserName&lt;/wsse:Username&gt;
        &lt;wsse:Password&gt;SomePassword&lt;/wsse:Password&gt;
      &lt;/wsse:UsernameToken&gt;
      &lt;wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"&gt;MII...SomeTokenString...
      &lt;/wsse:BinarySecurityToken&gt;
    &lt;/wsse:Security&gt;
  &lt;/soapenv:Header&gt;
  </code></pre>
  
  <p>Here's what I've tried but this results in UsernameToken and BinarySecurityToken being empty.</p>
  
  <p>App.config:</p>
  
  <pre><code>&lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="myBasicHttpBinding"&gt;
        &lt;security mode="Transport"&gt;
          &lt;transport clientCredentialType ="Certificate" proxyCredentialType="None" realm="" /&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;behaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="myBehavior"&gt;
        &lt;clientCredentials&gt;
          &lt;clientCertificate findValue="67...thumbprint...4b" x509FindType ="FindByThumbprint" storeLocation="LocalMachine" storeName="TrustedPeople"/&gt;
        &lt;/clientCredentials&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;client&gt;
    &lt;endpoint address="https://name.myserver.com/myservice/v1" binding="basicHttpBinding" bindingConfiguration="myBasicHttpBinding" behaviorConfiguration="myBehavior"
      contract="ServiceReferenceMyService.MyService" name="MyServiceEP"&gt;
      &lt;identity&gt;
        &lt;dns value ="CertName" /&gt;
      &lt;/identity&gt;
    &lt;/endpoint&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p>C# code:</p>
  
  <pre><code>UsernameToken usernameToken = new UsernameToken("SomeUserName", "SomePassword", PasswordOption.SendPlainText);
  
  var cert = new X509Certificate2("D:\\CertName.pfx", "SomePassword");
  var export = cert.Export(X509ContentType.Cert, "SomePassword");
  var base64 = Convert.ToBase64String(export);
  X509SecurityToken securityToken = new X509SecurityToken(cert);
  
  SecurityHeaderType securityHeaderType = new SecurityHeaderType();
  securityHeaderType.Any = new System.Xml.XmlElement[2];
  securityHeaderType.Any[0] = usernameToken.GetXml(new System.Xml.XmlDocument());
  securityHeaderType.Any[1] = securityToken.GetXml(new System.Xml.XmlDocument());
  
  ChannelFactory&lt;MyService&gt; channelFactory = new ChannelFactory&lt;MyService&gt;("MyServiceEP");
  
  MyService client = channelFactory.CreateChannel();
  GetProductDataRequestResponse responseData = client.GetProductData(new GetProductDataRequestRequest(securityHeaderType, serviceContext, requestData));
  
  ((IChannel)client).Close();
  channelFactory.Close();
  </code></pre>
  
  <p>Please disregard the two objects serviceContext and requestData -<br>
  serviceContext is a custom class to pass data required by the service<br>
  requestData is the request data (filter criteria) sent to the service for which results are expected.  </p>
  
  <p>The above code causes the soap request header to look like this but <strong>empty tags showing Removed is a problem</strong>. I want the actual values to appear. I also don't need the wsse:Nonce and wsu:Created elements either.</p>
  
  <pre><code>&lt;s:Header&gt;
      &lt;h:Security xmlns:h="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
          &lt;wsse:UsernameToken wsu:Id="SecurityToken-01f8a086-92b5-4aa2-8154-244061bdae5e" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;
              &lt;wsse:Username&gt;
                  &lt;!-- Removed--&gt;
              &lt;/wsse:Username&gt;
              &lt;wsse:Password&gt;
                  &lt;!-- Removed--&gt;
              &lt;/wsse:Password&gt;
              &lt;wsse:Nonce&gt;
                  &lt;!-- Removed--&gt;
              &lt;/wsse:Nonce&gt;
              &lt;wsu:Created&gt;2016-02-25T00:20:25Z&lt;/wsu:Created&gt;
          &lt;/wsse:UsernameToken&gt;
          &lt;wsse:BinarySecurityToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
              &lt;!-- Removed--&gt;
          &lt;/wsse:BinarySecurityToken&gt;
      &lt;/h:Security&gt;
  &lt;/s:Header&gt;
  </code></pre>
  
  <p>Can someone please point out what am I missing? Any help is much appreciated.</p>
  
  <p>Thank you!</p>