title: PHP SOAP send Binary Security Token
body: <p>Buissness Flow</p>
  
  <p>It has two steps
  1. Authenticate user and get the binary certificate.
  2. Use this certificate in header to communicate with other services.</p>
  
  <p>USING PHP </p>
  
  <p>Problem</p>
  
  <p>I send my credentials to a service which returns me a binary certificate.</p>
  
  <p>Then I use this binary certificate, encode it in base64 using base64_encode() method of PHP. Since I cant binary content in SOAP Request.</p>
  
  <p>The output which I gets is much smaller and different certificate, hence my call to other services fails giving me a invalid certificate error.</p>
  
  <p>USING SOAP UI for step 1</p>
  
  <p>However when I use SOAP UI for the above flow, it works perfectly fine. As soap ui also uses base64 encoding (that I have found out).
  PFB link
  <a href="http://my.safaribooksonline.com/book/-/9781849515665/13dot-miscellaneous-topics/id286798206" rel="nofollow">http://my.safaribooksonline.com/book/-/9781849515665/13dot-miscellaneous-topics/id286798206</a> </p>
  
  <p>I even tried to copy the certificate from SOAP UI and hardcode it in my PHP code. 
  As SOAP UI shows the certificate in base64 encoding</p>
  
  <p>Still call via PHP fails saying "Certificate is invalid".</p>
  
  <p>I am clueless about the issue. Any help would be appreciated.</p>
  
  <p>Below is SOAP UI CODE</p>
  
  <pre><code>    &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://ccc/ddd/zzzzzz/jjj/service/serviceName" xmlns:java="java:ccc.ddd.zzzzzz.zzzzzzzzzzz.ccc.lll.zzzzzz.ctx" xmlns:java1="java:ccc.ddd.zzzzzz.zzzzzzzzzzz.ccc.lll.zzzzzz.tttttt" xmlns:java2="java:ccc.ddd.zzzzzz.zzzzzzzzzzz.ccc.lll.zzzzzz.cMode"&gt;
          &lt;soapenv:Header xmlns:ca="http://ccc.ddd.zzzzzz.jjjj"&gt;
              &lt;ca:AID&gt;DataAID&lt;/ca:AID&gt;
              &lt;wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-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#X509v3" wsu:Id="XXXXXCertificate" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;Binary cintent in encoded format&lt;/wsse:BinarySecurityToken&gt;
              &lt;/wsse:Security&gt;
          &lt;/soapenv:Header&gt;
         &lt;soapenv:Body&gt;
            &lt;cus:opName&gt;
               &lt;cus:p1&gt;
                  &lt;!--Optional:--&gt;
                  &lt;java:ApId&gt;
                     &lt;!--Optional:--&gt;
                     &lt;java:Name&gt;&lt;/java:Name&gt;
                  &lt;/java:ApId&gt;
               &lt;/cus:p1&gt;
              &lt;/cus:opName&gt;
          &lt;/soapenv:Body&gt;
      &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>Below is request from PHP Soap Client</p>
  
  <pre><code>    &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="java:ccc.ddd.zzzzzz.zzzzzzzzzzz.ccc.lll.zzzzzz.ctx" xmlns:ns2="java:ccc.ddd.zzzzzz.zzzzzzzzzzz.ccc.lll.zzzzzz.tttttt" xmlns:ns1="http://ccc/ddd/zzzzzz/jjj/service/serviceName" xmlns:ns4="java:ccc.ddd.zzzzzz.zzzzzzzzzzz.ccc.lll.zzzzzz.cMode"" xmlns:ns5="http://ccc.ddd.zzzzzz.jjjj" xmlns:ns6="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
          &lt;SOAP-ENV:Header&gt;
              &lt;ns5:CallerID&gt;SE_SYS_1&lt;/ns5:CallerID&gt;
              &lt;ns5:CallID&gt;1556549759&lt;/ns5:CallID&gt;
              &lt;ns5:ApplicationID&gt;TEST_APP&lt;/ns5:ApplicationID&gt;
              &lt;ns5:CustomerID&gt;LH&lt;/ns5:CustomerID&gt;
              &lt;ns6:Security&gt;
                   &lt;BinarySecurityToken&gt;Copy pasted from soap ui in same encoding&lt;/BinarySecurityToken&gt;
              &lt;/ns6:Security&gt;
          &lt;/SOAP-ENV:Header&gt;
          &lt;SOAP-ENV:Body&gt;
              &lt;ns3:sortCustomerList&gt;
                  &lt;ns3:p1&gt;
                      &lt;ns1:ApplicationId&gt;
                          &lt;ns1:Name/&gt;
                      &lt;/ns1:ApplicationId&gt;
                  &lt;/ns3:p1&gt;
              &lt;/ns3:sortCustomerList&gt;
          &lt;/SOAP-ENV:Body&gt;
      &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>What I am not using is EncodingType ans valueType etc in BinarySecurityToken tag while sending request via PHP.</p>