title: Connecting to WS-Security protected Web Service with PHP
body: <p>I am trying to connect to a Web Service which is password protected and the url is https. I can't figure out how to authenticate before the script makes a request. It seems like it makes a request as soon as I define the service. For instance, if I put in:</p>
  
  <pre><code>$client = new SoapClient("https://example.com/WSDL/nameofservice",
         array('trace' =&gt; 1,)
  );
  </code></pre>
  
  <p>and then go to the site on the browser, I get:</p>
  
  <pre><code>Fatal error: Uncaught SoapFault exception: 
  [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from
  'https://example.com/WSDL/nameofservice' in /path/to/my/script/myscript.php:2 
  Stack trace: #0 /path/to/my/script/myscript.php(2): 
  SoapClient-&gt;SoapClient('https://example...', Array) #1 {main} thrown in 
  /path/to/my/script/myscript.php on line 2
  </code></pre>
  
  <p>If I try defining the service as a Soap Server, like:</p>
  
  <pre><code>$server= new SoapServer("https://example.com/WSDL/nameofservice");
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;SOAP-ENV:Body&gt;
  &lt;SOAP-ENV:Fault&gt;
  &lt;faultcode&gt;WSDL&lt;/faultcode&gt;
  &lt;faultstring&gt;
  SOAP-ERROR: Parsing WSDL: 
  Couldn't load from 'https://example.com/WSDL/nameofservice'
  &lt;/faultstring&gt;
  &lt;/SOAP-ENV:Fault&gt;
  &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>I haven't tried sending a raw request envelope yet to see what the server returns, but that may be a workaround. But I was hoping someone could tell me how I can set it up using the php built-in classes. I tried adding "userName" and "password" to the array, but that was no good. The problem is that I can't even tell if I'm reaching the remote site at all, let alone whether it is refusing the request.</p>