Send multiple calls to Soap in php

Asked

Viewed 74 times

1

I am studying the use of SOAP in PHP, and I have a webservice that when I send the number of an employee’s registration it returns the name of the employee and the sector, but I would like to send 5 number plates at the same time and return the name of 5 employees, how can I adapt my current code sending only one number at a time ?

My code:

<?php

$params  = array("soap_version"=> SOAP_1_2,
                "trace"=>1,
                "exceptions"=>0,
                );

$client = @new SoapClient('http://webserviceteste.com.br/WebService/WebService.asmx?WSDL',$params);

$retval = $client->ObterCadastro_S(
    array(
        'matricula'  => '0000',
        'inscricao'  => '0000',
    )
);

echo $retval->ObterCadastro_SResult->NomeFuncionario;
echo $retval->ObterCadastro_SResult->SetorFuncionario;

?>

Code for 3 parameter array

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sem título</title>
</head>

<body>
<?php

//array que guarda 'matricula' => 'inscricao'
//'0001' => '1234',

$arrayMatriculasInscricoes = array("dados" => array("matricula" => 0001, "inscricao" => 1234, "cpf" => 123456789));

echo $arr["dados"]["matricula"];
echo $arr["dados"]["inscricao"];
echo $arr["dados"]["cpf"];

foreach ($arrayMatriculasInscricoes as $i => $inscricao) {

    //faz a consulta
    $retval = $client->ObterCadastro_S(
        array(
            'matricula'  => $i,
            'inscricao'  => $inscricao
        )
    );
    echo $retval->ObterCadastro_SResult->NomeFuncionario;
    echo $retval->ObterCadastro_SResult->SetorFuncionario;
}

?>
</body>
</html>

Valew

1 answer

0

You can use a repeat loop, follow:

in the following example, it is necessary that the arrays are in mutual order. in the ex: registration=0001, registration=99999, anything=34563, variable=34534

$arrayMatriculas = array('0001', '0002', '0003', '0004', '0005');
$arrayInscricoes = array('99999', '88888', '77777', '66666', '55555');
$arrayQualquerCoisa = array('34563', '34532', '23414', '45756', '45675');
$arrayVariavel = array('34534', '56753', '23435', '36786', '34567');

foreach ($arrayMatriculas as $i => $matricula) {

    //faz a consulta
    $retval = $client->ObterCadastro_S(
        array(
            'matricula'  => $matricula,
            'inscricao'  => $arrayInscricoes[$i],
            'qualquerCoisa' => $arrayQualquerCoisa[$i],
            'qualquerVariavel' => $arrayVariavel[$i]
        )
    );
    echo $retval->ObterCadastro_SResult->NomeFuncionario;
    echo $retval->ObterCadastro_SResult->SetorFuncionario;
}
  • Cool, and if I want to send the number of the registration and the registration, as I can do ?

  • ai have to see if your Get Registration function receives the $registration variable. has how to post this function here?

  • Actually I need to pass the registration and registration as I can do ?

  • I don’t understand very well... today you can send these two values? if yes, post the code here.

  • I edited the code of my question, I need to send the registration together with the employee registration so that the system returns the name of the employee.

  • edited my answer.

  • no, ai indico estes link para você entender o funcionamento de arrays e de laços em php. follow [link] http://php.net/manual/en/language.types.array.php) and (http://php.net/manual/en/control-structures.foreach.php)

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.