Consume web service (WSDL) in PHP

Asked

Viewed 6,384 times

0

I don’t have much practical experience with web services. I need to use some methods of this: https://epfweb.safra.com.br/WCF/SvcContratos.svc?wsdl

Could someone help me in how to connect with it in PHP and get the return?

For example: There is a method called Gerartoken() which receives 3 parameters: Dfusuario (Type: string), Password (Type: string), Idtipoconsulta (Type: Typoconsulta).

How could I use the web service to access this method and get its return (the token, in this case) in a variable?

2 answers

1

Try this code:

<?php
$client = new SoapClient('https://epfweb.safra.com.br/WCF/SvcContratos.svc?wsdl');
$function = 'GerarToken';
$arguments= array('GerarToken' => array(
    'DsUsuario'      => 'CSB18135',
    'DsSenha'        => 'Bb232736'
));


$result = $client->__soapCall($function, $arguments);
echo 'Response: ';
print_r($result);

?>

You may need to install the extension SoapClient.

PHP: How do I install Soap Extension?

Be sure to see:

Using SOAP with PHP

  • I got this error return: Fatal error: Uncaught Soapfault Exception: [a:Internalservicefault] The server was Unable to process the request due to an Internal error. For more information about the error, either turn on Includeexceptiondetailinfaults (either from Servicebehaviorattribute or from the <serviceDebug> Configuration behavior) on the server in order to send the Exception information back to the client, or turn on tracing as per the Microsoft . NET Framework SDK Documentation and Inspect the server trace logs. .

  • It is likely that the Safra webservice requires an authentication, it would be interesting to ask the Safra the documentation of the webservice.

-1

<?php
$client = new SoapClient('https://epfweb.safra.com.br/WCF/SvcContratos.svc?wsdl');
$arguments = [
    'GerarToken' => [
        'objLogin' => [
             'DsUsuario' => 'CSB18135',
             'DsSenha'   => 'Bb232736'
        ]   
    ]
];

$result = $client->__soapCall('GerarToken', $arguments);
echo 'Response: ';
print_r($result);

?>

Browser other questions tagged

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