title: Remove Timestamp element from Security
body: <p>All the geeks will say WSE is outdated.. Thats ok for me right now.. Just trying to find a solution for my problem
  Trying to consume a Java webservice using WSE. 
  In the outgoing soap request has an security has additional time stamp node. 
  My outgoing soap request looks like this </p>
  
  <pre><code> &lt;soap:Header&gt;
      &lt;wsa:Action wsu:Id="Id-6209d12b-20bf-407e-ac72-533d0f671a2c"&gt;&lt;/wsa:Action&gt;
      &lt;wsa:MessageID wsu:Id="Id-280fe225-2f80-4f37-b5d4-120146fc7dec"&gt;urn:uuid:a427b687-6f52-4689-9df2-c2e3c6d9ea1a&lt;/wsa:MessageID&gt;&lt;
      wsa:ReplyTo wsu:Id="Id-bc623f16-761c-4e03-a23e-aa70bd9b8d34"&gt;&lt;wsa:Address&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:Address&gt;&lt;/wsa:ReplyTo&gt;
      &lt;wsa:To wsu:Id="Id-b8607eed-cb9e-426b-a5dc-51d7855c32e1"&gt;https://service100.emedny.org:9047/MHService&lt;/wsa:To&gt;
     &lt;wsse:Security soap:mustUnderstand="1"&gt;
     &lt;wsu:Timestamp wsu:Id="Timestamp-cbeb0310-93bf-4f39-a44d-3516b32b40e6"&gt;&lt;wsu:Created&gt;2013-06-20T20:19:47Z&lt;/wsu:Created&gt;&lt;wsu:Expires&gt;2013-06-20T20:24:47Z&lt;/wsu:Expires&gt;&lt;/wsu:Timestamp&gt;&lt;wsse:BinarySecurityToken ValueType&gt;&lt;/BinarySecurityToken&gt;....&lt;/soap:Header&gt;
  </code></pre>
  
  <p>..
  I am trying to remove the action, messageid, replyto, timestamp elements</p>
  
  <p>So the outgoing should look like </p>
  
  <pre><code>   &lt;soap:Header&gt;
      &lt;wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
    &lt;wsse:BinarySecurityToken........&gt;
  &lt;/soap:header&gt;
  </code></pre>
  
  <p>How would I remove the 4 elements + timestamp node from security.I am using WSE3.0. Sorry not Wcf rt now 
  This is what I tried.</p>
  
  <pre><code>Step1
  
  Create a custom policy assertion by deriving from Microsoft.Web.Services3.Design.PolicyAssertion.
  
          namespace UsernameAssertionLibrary
      {
          public class UsernameClientAssertion : SecurityPolicyAssertion, PolicyAssertion
          {
              private string username;
              private string password;
  
              public UsernameClientAssertion(string username, string password)
              {
                  this.username = username;
                  this.password = password;
              }
  
              public override SoapFilter CreateClientOutputFilter(FilterCreationContext context)
              {
                  return new ClientOutputFilter(this, context);
              }
  
              public override SoapFilter CreateClientInputFilter(FilterCreationContext context)
              {
                  // we don't provide ClientInputFilter
                  return null;
              }
  
              public override SoapFilter CreateServiceInputFilter(FilterCreationContext context)
              {
                  // we don't provide any processing for web service side
                  return null;
              }
  
              public override SoapFilter CreateServiceOutputFilter(FilterCreationContext context)
              {
                  // we don't provide any processing for web service side
                  return null;
              }
              public override System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.KeyValuePair&lt;string, Type&gt;&gt; GetExtensions()
              {
                  return new KeyValuePair&lt;string, Type&gt;[] { new KeyValuePair&lt;string, Type&gt;("UsernameClientAssertion", this.GetType()) };
              }
  
              public override void ReadXml(XmlReader reader, IDictionary&lt;string, Type&gt; extensions)
              {
                  reader.ReadStartElement("UsernameClientAssertion");
              }
  
  
              #region ClientOutputFilter
              class ClientOutputFilter : SendSecurityFilter
              {
                  UsernameClientAssertion parentAssertion;
                  FilterCreationContext filterContext;
  
                  public ClientOutputFilter(UsernameClientAssertion parentAssertion, FilterCreationContext filterContext)
                      : base(parentAssertion.ServiceActor, false, parentAssertion.ClientActor)
                  {
                      this.parentAssertion = parentAssertion;
                      this.filterContext = filterContext;
                  }
  
                  public override void SecureMessage(SoapEnvelope envelope, Security security)
                  {
                      X509SecurityTokenManager objCertTokenManager = (X509SecurityTokenManager)SecurityTokenManager.GetSecurityTokenManagerByTokenType(WSTrust.TokenTypes.X509v3);
                      objCertTokenManager.DefaultKeyAlgorithm = "RSA15";
                      objCertTokenManager.DefaultSessionKeyAlgorithm = "TripleDES";
  
                      X509Certificate2 cert = GetCertificateFromStore("LMWARD");
                      X509SecurityToken x5091 = new X509SecurityToken(cert);
  
                      X509Certificate2 cert2 = GetCertificateFromStore("DPMedsHistory");
                      X509SecurityToken x5092 = new X509SecurityToken(cert2);
                      UsernameToken userToken = new UsernameToken(
                          parentAssertion.username,
                          parentAssertion.password,
                          PasswordOption.SendNone); // we don't send password over network
                                                    // but we just use username/password to sign/encrypt message
  
                      // Add the token to the SOAP header.
                      security.Tokens.Add(x5091);
                      security.Tokens.Add(x5092);
                      security.Tokens.Add(userToken);
  
  
                      // Sign the SOAP message by using the UsernameToken.
                      MessageSignature sig = new MessageSignature(x5091);
                      security.Elements.Add(sig);
  
                      // encrypt BODY
                      EncryptedData data = new EncryptedData(x5092);
                      // add ancrypted data to the security context
                      security.Elements.Add(data);
                  }
                  private static X509Certificate2 GetCertificateFromStore(string certName)
                  {
  
                      // Get the certificate store for the current user.
                      X509Store store = new X509Store(StoreLocation.LocalMachine);
                      try
                      {
                          store.Open(OpenFlags.ReadOnly);
  
                          // Place all certificates in an X509Certificate2Collection object.
                          X509Certificate2Collection certCollection = store.Certificates;
                          X509Certificate2Collection signingCert = certCollection.Find(X509FindType.FindBySubjectName, certName, true);
  
                          if (signingCert.Count == 0)
                              return null;
                          // Return the first certificate in the collection, has the right name and is current. 
                          return signingCert[0];
                      }
                      finally
                      {
                          store.Close();
                      }
  
                  }
              }
              #endregion
          }
      }
  
  Step2
  This is my wse3Policy.Config 
  
      &lt;policies xmlns="http://schemas.microsoft.com/wse/2005/06/policy"&gt;
        &lt;extensions&gt;
          &lt;extension name="usernameAssertion" 
            type="UsernameAssertionLibrary.UsernameServiceAssertion, 
                                           UsernameAssertionLibrary" /&gt;
        &lt;/extensions&gt;
        &lt;policy name="ServerPolicy"&gt;
          &lt;usernameAssertion /&gt;
        &lt;/policy&gt;
      &lt;/policies&gt;
  
   Step3
  
       namespace.Service1 MHs = new Service1();
              UsernameClientAssertion assert = new UsernameClientAssertion("user", "pwd");
  
              // create policy
              Policy policy = new Policy();
              policy.Assertions.Add(assert);
  
              // and set it to web service
              MHs.SetPolicy(policy);
          Mhs.Method();
  </code></pre>
  
  <p>I am not getting any error. It has a warning in the policy file that 
  The element policy has an invalid child element usernameassertion.List of possible elements are .......
  The security timestamp element, ActionId, mesageId, replyTo, wsa elements still appear in the outgoing soap. 
  What am I missing here.. </p>