Hi,

I need to connect our Drupal 8 using SOAP to consume services, but i can´t find any documentation about that. Can somebody help me?

I will need firt use login/pass to connect to the external server and after that i will need create a display some pages with views and their menus to access depending of the user role.

If somebody can tell me where i can find documentation or videos about it i will appreciate so much.

Thanks

Comments

slewazimuth’s picture

luis_mejia’s picture

I was searching a lot of videos, and content about SOAP service conexion with php and drupal, and finally i think i understood how it work, i had create my test_server.php and test_client.php and everything was fine using soap, but, now i'm try to connect using my own custom module with a real server and i just have a bad response:

"array(3) { [0]=> string(38) "LoginResponse Login(Login $parameters)" [1]=> string(41) "LogoutResponse Logout(Logout $parameters)" [2]=> string(65) "IsValidSessionResponse IsValidSession(IsValidSession $parameters)" } NULL"

Can somebody tell me what i'm doing bad here? Drupal 8:

Custom_module/src/myservice.php

****** Here is my code inside my service ******

ini_set ("display_errors", true);


namespace Drupal\areadum;
use \SoapClient;

class areadumConectorService
{

  public function identificarUsuario()
  {

    // Create the object
    echo "********** INICIO DEL LOGIN **********<br>";
    $soapLoginOptions = array(
      "trace" => true,
      'exceptions' => true,
    );


    $soapLogin = new soapClient("http://myserver.svc?WSDL", $soapLoginOptions);
    echo "********** VOLCADO DE FUNCIONES DE AUTENTICACION **********<br>";
    echo "<pre>"; var_dump ($soapLogin->__getFunctions()); echo "</pre>";
    echo "********** VOLCADO DE TIPOS DE AUTENTICACION **********<br>";
    echo "<pre>"; var_dump ($soapLogin->__getTypes()); echo "</pre>";

    // preparamos los parámetros del login
    $soapLoginParameters = array(
      'userName'	=> 'dum1@dev.com',
      'password'	=> sha1('develop') // OJO!!!!!! el password tiene que encriptarse son sha1
    );

    echo "********** LLAMADA AL LOGIN ********** <br>";
    // llamamos a la funcion Login
    $error = 0;
    try {
      $soapLoginResponse = $soapLogin->__soapCall("Login", array("parameters" => $soapLoginParameters));
      $soapToken = $soapLoginResponse->LoginResult->SessionToken;
      echo "Token: " . $soapToken ."<br>";
    } catch (SoapFault $fault) {
      $error = 1;
      echo "ERROR: ".$fault->faultcode."-".$fault->faultstring.".";
    }
    echo "********** FINAL DEL LOGIN **********<br><br><br>";


    // y ahora vamos a otro webservice con el token

    echo "********** INICIO DE LA RECUPERACIÓN DE DATOS DE USUARIO **********<br>";
    $soapUserDataOptions = array(
      "trace" => true,
      'exceptions' => true,
    );

    $soapUserData = new SoapClient("http://myserver.svc?WSDL", $soapUserDataOptions);
    echo "********** VOLCADO DE FUNCIONES DE AUTENTICACION **********<br>";
    echo "<pre>"; var_dump ($soapUserData->__getFunctions()); echo "</pre>";
    echo "********** VOLCADO DE TIPOS DE AUTENTICACION **********<br>";
    echo "<pre>"; var_dump ($soapUserData->__getTypes()); echo "</pre>";

    $headerbody = array('SessionToken' => $soapToken );
    $header = new SoapHeader('ns','SessionToken',$soapToken,false);
    $soapUserData->__setSoapHeaders($header);

    try {
      $soapUserDataResponse = $soapUserData->GetUserAccountAdmin();
      var_dump ($soapUserDataResponse);
    } catch (SoapFault $fault) {
      $error = 1;
      echo "ERROR: ".$fault->faultcode."-".$fault->faultstring.".";
    }

    echo "********** FINAL DE LA RECUPERACIÓN DE DATOS DE USUARIO **********<br><br><br>";

    $output = array(
    '#markup'=>('Message test'),
    );
    return $output;
  }
}

sidharthsreekumar’s picture

Hi Luis,  were you able to successfully implement SOAP services in Drupal 8? I am also trying to make it work. If possible could you help me with this?

Nilesh Chhantbar’s picture

Hi Sidharthshreekumar, were you able to identify fix of this? If yes can you please share some info on fix?