You are here

public function WSClientSOAPEndpoint::client in Web service client 7

2 calls to WSClientSOAPEndpoint::client()
WSClientSOAPEndpoint::call in wsclient_soap/wsclient_soap.module
Calls the SOAP service.
WSClientSOAPEndpoint::initializeMetadata in wsclient_soap/wsclient_soap.module
Retrieve metadata from the WSDL about available data types and operations.

File

wsclient_soap/wsclient_soap.module, line 30
Web service client SOAP support.

Class

WSClientSOAPEndpoint
A remote endpoint type for invoking SOAP services.

Code

public function client() {
  if (!isset($this->client)) {
    $options['exceptions'] = TRUE;
    if ($this->service->type == 'soap 1.2') {
      $options['soap_version'] = SOAP_1_2;
    }

    // Handle Basic HTTP authentication.
    if (!empty($this->service->settings['authentication']['basic'])) {
      $this->service->settings['options']['login'] = $this->service->settings['authentication']['basic']['username'];
      $this->service->settings['options']['password'] = $this->service->settings['authentication']['basic']['password'];
    }
    if (!empty($this->service->settings['options'])) {
      $options += $this->service->settings['options'];
    }
    try {
      $this->client = new SOAPClient($this->url, $options);
    } catch (SoapFault $e) {
      throw new WSClientException('Error initializing SOAP client for service %name', array(
        '%name' => $this->service->name,
      ));
    }

    // Handle WSS style secured webservice.
    // https://www.drupal.org/node/2420779
    if (!empty($this->service->settings['authentication']['wss'])) {
      $this->client
        ->__setSoapHeaders(new WSSESecurityHeader($this->service->settings['authentication']['wss']['username'], $this->service->settings['authentication']['wss']['password']));
    }
    elseif (!empty($this->service->global_header_parameters)) {
      $header_parameters = $this->service->global_header_parameters;
      $data_types = $this->service->datatypes;
      $headers = array();
      foreach ($header_parameters as $type => $parameter) {
        $name_space = $parameter['name space url'];
        $data_type = $data_types[$type];
        $soap_vars = array();
        foreach ($data_type['property info'] as $name => $property) {
          $soap_vars[] = new SoapVar($property['default value'], XSD_STRING, NULL, NULL, $name, $name_space);
        }
        $header_data = new SoapVar($soap_vars, SOAP_ENC_OBJECT, NULL, NULL, $type, $name_space);
        $headers[] = new SoapHeader($name_space, $type, $header_data, FALSE);
      }
      $this->client
        ->__setSoapHeaders($headers);
    }
  }
  return $this->client;
}