title: How to consume a WCF Web Service that uses custom username validation with a PHP page?
body: <p>I'm having hard time consuming a secure WCF Web Service from a PHP site. My knowledge in PHP are limited, I found various examples on the Web but didn't succeeded making them working yet.</p>
  
  <p>I have a Silverlight application that also consume this WebService and it works fine. But when I run the PHP site, I get this error :</p>
  
  <blockquote>
    <p>MessageSecurityException: Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties.   This can occur if the service is configured for security and the client is not using security.</p>
  </blockquote>
  
  <p>I also tried to change the customBinding to a basicHttpBinding. When I do that, the Custom Username validator is not called anymore. But, using basicHttpBinding and removing credentials validation on my WCF Service "works" (Besides the fact that it is unsecured). So the problem seems to related to the security message.</p>
  
  <p>Could someone give me a working example or tutorial that could help me making this PHP page works?</p>
  
  <p>Here is my PHP code :</p>
  
  <pre><code>    $options = array( 
              'soap_version'  =&gt; SOAP_1_1, 
              'exceptions'    =&gt; true, 
              'trace'         =&gt; 1, 
              'cache_wsdl'    =&gt; WSDL_CACHE_NONE,
              'Username'      =&gt; 'MyUserName', 
              'password'      =&gt; 'MyPassword');
  
  $client = new SoapClient('https://UrlToService/Service.svc?wsdl', $options); 
  
  try
  {
      $phpresponse = $client-&gt;Get(); 
  
      print $phpresponse-&gt;GetResult-&gt;Version;
      echo "&lt;/b&gt;&lt;BR/&gt;&lt;BR/&gt;";
  }
  catch(Exception $e) 
  { 
      echo "&lt;h2&gt;Exception Error!&lt;/h2&gt;&lt;/b&gt;"; 
      echo $e-&gt;getMessage(); 
      echo "&lt;BR/&gt;&lt;BR/&gt;";
  }
  </code></pre>
  
  <p><strong>WCF Configuration</strong></p>
  
  <pre><code>&lt;behavior name="sslBehavior"&gt;
     &lt;serviceMetadata httpsGetEnabled="true" /&gt;
     &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
     &lt;serviceCredentials&gt;
        &lt;userNameAuthentication userNamePasswordValidationMode="Custom"   customUserNamePasswordValidatorType="MyNamespace.ServiceUserNameValidator, MyNamespace" /&gt;
     &lt;/serviceCredentials&gt;
     &lt;serviceSecurityAudit
      auditLogLocation="Application"
      serviceAuthorizationAuditLevel="Failure"
      messageAuthenticationAuditLevel="Failure"
      suppressAuditFailure="true" /&gt;
  &lt;/behavior&gt;
  
  &lt;customBinding&gt;
      &lt;binding name="sslCustomBinding"&gt;
        &lt;security authenticationMode="UserNameOverTransport" includeTimestamp="true" allowInsecureTransport="true"&gt;
          &lt;localServiceSettings maxClockSkew="00:10:00" /&gt;
          &lt;localClientSettings maxClockSkew="00:10:00" /&gt;
          &lt;secureConversationBootstrap /&gt;
        &lt;/security&gt;
        &lt;textMessageEncoding messageVersion="Soap11" /&gt;
        &lt;httpsTransport /&gt;
      &lt;/binding&gt;
    &lt;/customBinding&gt;
  
  &lt;service behaviorConfiguration="sslBehavior" name="MyNamespace.Services.Service"&gt;
      &lt;endpoint address="" binding="customBinding" 
                bindingConfiguration="sslCustomBinding" contract="MyNamespace.ServiceContracts.IService" /&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="https://UrlToService/Services/" /&gt;
        &lt;/baseAddresses&gt;
      &lt;/host&gt;
    &lt;/service&gt;
  </code></pre>