title: PHP SoapClient to call a soap method with authentication
body: <p>I am trying to access a webservice (JAX-WS) with wsdl using php (5.3.5). Following is the code I am using :</p>
  
  <pre><code>class insoapauth 
  { 
      public $Username; 
      public $Password; 
  
      public function __construct($username, $pass) 
      { 
          $this-&gt;Username = $username; 
          $this-&gt;Password = $pass; 
      } 
  } 
  $client = new SoapClient("http://192.168.124.11:8080/cx-subscriberdata/CXSubscriberAdmin?wsdl", array( "login" =&gt; "SOAPDW", "password" =&gt; "DW@2012"));
  
     // Create the header 
    $auth         = new insoapauth("SOAPDW", "DW@2012"); 
    $header       = new SoapHeader("http://192.168.124.11:8080/cx-subscriberdata/CXSubscriberAdmin", "APICredentials", $auth, false); 
  try {
  
    $result = $client-&gt;__soapCall("getDataWS", array( 
      "CrmSearchInformation" =&gt; array( 
          "searchKeyValue"        =&gt; "93700801021"        
      ) 
  )); 
  
    echo("&lt;br/&gt;Returning value of __soapCall() call: ".$result);
  
  }catch(SoapFault $exception)
  {
      print_r("Got issue:&lt;br/&gt;") ;
    var_dump($exception);
  }
  </code></pre>
  
  <p>Alternatively I tried another way using the SoapHeader and supplying it while the method call. But I am always getting the SoapFault exception :</p>
  
  <blockquote>
    <p>Could not connect to host</p>
  </blockquote>
  
  <p>More details exception:</p>
  
  <blockquote>
    <p>SoapFault exception: [HTTP] Could not connect to host in
    C:\wamp\www\SOAPTest\client\insoaptest.php:103 Stack trace: #0
    [internal function]: SoapClient->_<em>doRequest('</em>_soapCall('getDataWS',
    Array) #2 {main}</p>
  </blockquote>
  
  <p>However, using soapUI I can connect to the soapsever and can call the soapmethod with the same credentials.
  Following is some example code to access the WS - I guess it's in Java- that comes with the manual:</p>
  
  <pre><code>INBeanService service = new INBeanService();
  CXINWS wsPort = service.getCXINWSPort();
  String username = "crmtestuser";
  String password = "crmpassword";
  BindingProvider bp = (BindingProvider) wsPort;
  bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
  bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  try {
  CrmSearchInformation crmSearchInfo = new CrmSearchInformation();
  crmSearchInfo.setSearchKeyValue(msisdn);
  CrmSearchResult result = wsPort.getDataWS(crmSearchInfo);
  //handle result
  System.out.println("Result state: " + result.getSearchResultState());
  } catch (NxWsException e) {
  // handle exceptions
  }
  </code></pre>
  
  <p>Can anybody please show me some light how I can access a wsdl webservice from php with authentication ?</p>