Send multiple calls to soap in php

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 employee's name and the sector, but I would like to send 5 registration numbers to the same one time and return the name of 5 employees, how can I adapt my current code that sends 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;

?>

3-parameter array code

<!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

    
asked by anonymous 08.11.2015 / 00:31

1 answer

0

You can use a repetition loop, as follows:

In the following example, the arrays must be in mutual order. no ex: enrollment = 0001, enrollment = 99999, anyCourse = 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;
}
    
08.11.2015 / 01:03