Question:
I'm consuming a SOAP WebService and I'm encountering the following problem: The WebService has two functions. In PHP, using the SoapClient class, I created the client and consumed the first function with no problem. But when I try to use the second function, it returns a bunch of gibberish errors. But when I try to consume this second function using SoapUI, the second function sends the return correctly. My question is: can it be an error in the WebService? But if it is, how does SoapUI manage to consume it?
In addition, I have a certain suspicion that the error may be in the WebService, because when I tried to import the WSDL from it in Java or Python, the import fails. And this never happened with other web-services I've consumed. The WebService path is: http://wcaixa.datasysonline.net/wsDadosCaixa.asmx?wsdl
My PHP code:
<?php
$clientesoap = new SoapClient("http://wscaixa.datasysonline.net/wsDadosCaixa.asmx?wsdl", array(
'cache_wsdl' => WSDL_CACHE_NONE
));
$xml = "<cartoes>";
$xml .= "<lancamento>";
$xml .= "<pedido>XXXX-XXXXX</pedido>";
$xml .= "<parcela>1</parcela>";
$xml .= "<nsu>666666</nsu>";
$xml .= "<valorParcela>36</valorParcela>";
$xml .= "<valorLiquido>35</valorLiquido>";
$xml .= "<dtVencimento>10/03/2015</dtVencimento>";
$xml .= "<dtAntecipacao>12/03/2015</dtAntecipacao>";
$xml .= "<dtLiquidacao>12/03/2015</dtLiquidacao>";
$xml .= "<taxaAntecipacao>2</taxaAntecipacao>";
$xml .= "</lancamento>";
$xml .= "</cartoes>";
$param = new stdClass();
$param->Token = 'xxxxxxxxxxxxxxxxxxxxxxx';
$param->Xml = $xml;
$resultado = $clientesoap->AtualizarConciliacao($param);
// a funcao abaixo funciona, mas a de cima (AtualizarConciliacao) dá erro:
// $param->Data '2016-03-03';
// $resultado = $clientesoap->BaixarVendasCartao($param);
print_r($resultado);
?>
Answer:
Hello Paul.
I took the liberty of porting your code to visual studio and was able to pinpoint the problem.
The error displayed indicates that the token would be null, and it is. If you look at the parameters sent, you will see that you only pass the XML and not the token as is the method definition. Even passing it, I got the same error message if you send a token in string format. For it to work correctly you need to convert the token to base64 string.
In C#, your token conversion would look like this:
var encoding = System.Text.Encoding.UTF8;
byte[] textAsBytes = encoding.GetBytes(token);
string base64String = System.Convert.ToBase64String(textAsBytes);
So, when you call, you call: client.UpdateConciliacao(base64String, docxml);
The error message will occur, but now it will indicate "Invalid token.", which is a standard message from the webservice when validating the token.
From what I read in the PHP documentation , the command for you would be:
(...)
$tokenBase64 = base64_encode($token);
$resultado = $clientesoap->AtualizarConciliacao($tokenBase64, $xml);
I hope it helps. abs