title: BinarySecurityToken with wcf
body: <p>I've successfully tested connecting to a SOAP service using SoapUI (5.1.2), and now I need to generate the soap requests from a C# application.</p>
  
  <p>I added a keystore to SoapUI, where the certificate is stored, and the security configuration from SoapUI is fairly straighforward...</p>
  
  <p><img src="https://i.stack.imgur.com/fuKXV.png" alt="SoapUI Screencap showing simple security settings"></p>
  
  <p>And here is a working sample request (details removed)</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:typ="url.removed"&gt;
    &lt;soap:Header&gt;
      &lt;wsse:Security 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: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#X509PKIPathv1" 
                              wsu:Id="X509-08AC5A2756F38141D814355761534501"&gt;    &lt;!-- data removed --&gt;&lt;/wsse:BinarySecurityToken&gt;
        &lt;ds:Signature Id="SIG-08AC5A2756F38141D814355761534824" 
                  xmlns:ds="http://www.w3.org/2000/09/xmldsig#"&gt;
          &lt;ds:SignedInfo&gt;
            &lt;ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"&gt;
              &lt;ec:InclusiveNamespaces PrefixList="soap typ" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/&gt;
            &lt;/ds:CanonicalizationMethod&gt;
            &lt;ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/&gt;
          &lt;/ds:SignedInfo&gt;
          &lt;ds:SignatureValue&gt;&lt;!-- data removed --&gt;&lt;/ds:SignatureValue&gt;
          &lt;ds:KeyInfo Id="KI-08AC5A2756F38141D814355761534752"&gt;
            &lt;wsse:SecurityTokenReference 
          wsse11:TokenType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" 
          wsu:Id="STR-08AC5A2756F38141D814355761534763" 
          xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"&gt;
              &lt;wsse:Reference URI="#X509-08AC5A2756F38141D814355761534501" 
                          ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1"/&gt;
            &lt;/wsse:SecurityTokenReference&gt;
          &lt;/ds:KeyInfo&gt;
        &lt;/ds:Signature&gt;
      &lt;/wsse:Security&gt;
  
    &lt;/soap:Header&gt;
    &lt;soap:Body  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;
      &lt;typ:SoapDataRequest&gt;
        &lt;header&gt;
          &lt;dataremoved /&gt;
        &lt;/header&gt;
        &lt;bodyremoved /&gt;
      &lt;/typ:SoapDataRequest&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>I'm trying to programmatically create the bindings/configuration required, I already have the web reference imported into my project, just need to select the right combination from the myriad of options in wcf to get this working. If I don't provide the SSL cert required, it is an obvious error, so I know I'm fetching the certificate correctly from cert store (as opposed to *.pfx file from soupUI), but eveything else fails with "Policy Falsified", which is a security mismatch as far as I can see.</p>