Webservice returns to Soapui, but does not return to PHP

Asked

Viewed 1,408 times

8

I am consuming a SOAP Webservice and I am found the following problem: Webservice has two functions. In PHP, using the Soapclient class, I created the client and consumes the first function without problem. But when I try to use the second function, it returns me a lot of errors without nexus. But when I try to consume this second function using Soapui, the second function sends the return correctly. My question is: can it be a mistake in Webservice? But if it is, how can Soapui consume the same?

In addition, I have a certain suspicion that the error may be even in Webservice, because when I tried to import WSDL from it in Java or Python, the import fails. And that’s never happened with other web-services I’ve consumed. The path to Webservice is: http://wscaixa.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);

?>
  • My PHP code: http://pastebin.com/Er3NRekz

  • Error returned by PHP: http://pastebin.com/Up3mGp6N

  • Paulo you could add there in the statement of your question the code snippet , imagine that someone in the future has the same problem and your link is no longer available to access.

  • 1

    string Name, already pasted the code. Grateful for the tip.

  • By error message it seems that token is being sent null.

  • Without the true token it is not possible to reproduce your problem. WS is also not the best developed. WDSL should be self documenting and spell out exactly what fields it expects, not a named string xml.

Show 1 more comment

1 answer

0

Hello, Paulo.

I took the liberty of transporting your code to the visual studio and managed to identify the problem.

The error shown indicates that the token would be null, and indeed it is. If you look at the sent parameters, 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. To function properly you need to convert the token to Base64 string.

In C#, the conversion of your token would be 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.Updatelogin(base64String, docxml);

The error message will occur, but will now be indicating "Invalid Token." which is a standard webservice message in token validation.

From what I read in documentation from PHP, the command for you would be:

(...)   
$tokenBase64 = base64_encode($token);
$resultado = $clientesoap->AtualizarConciliacao($tokenBase64, $xml);

I hope it helps. Abs

  • Andre, I even tried your solution, but it didn’t work. But I figured the way I’m sending the token is not incorrect, because the other function works by sending the token the same way: $param->Token = 'xxxxxxxxxxxxxxxxx'; $param->Date '2016-03-03'; $result = $clientesoap->Downloadscartao($param);

  • Andre Mesquita, another thing: if you notice the error message that PHP is returning to me, return that it is a C# error coming from the webservice code itself. It even says the C# file name of the server’s webservice: c: tfs-csjs Dts_wscaixa Database Data.Cs system

  • Yes, the error occurs in the code with you in Data.Cs (Value cannot be null). But if you notice, the error occurs because at the time it tries to transform the null token you sent to the default string gives the error. In my view there are two errors: The first and most important is that the token is not being passed to the function. If you open the URL of the service you have placed, you will see in XML that the Update function asks for two parameters and not one. The other is the type of string, but if the token is correct, it should not occur.

  • André, see there in my code that I am passing the two parameters: $param = new stdClass(); $param->Token = 'here is the token'; $param->Xml = $xml; $result = $clientesoap->Updatingthe token($param); I am sure that the token is being passed. Notice that it goes inside the $param array. Even another function of the webservice works like this. The problem is in this function.

  • Tries: $token = 'xxxxxxxxxxxxxxxxxxxxxxx'; $resultado = $clientesoap->AtualizarConciliacao($token, $xml);

  • And André, remembering that the other function works correctly in the same way: $param = new stdClass(); $param->Token = 'here goes the token'; $param->Date '2016-03-03'; $result = $clientesoap->Downloadscarndatao($param);

  • In this case, the ideal would be to send so, I believe: am = new stdClass(); $param->Token = base64_encode('xxxxxxxxxxxxxxxxxxxxxxx');$param->Xml = $xml;

Show 2 more comments

Browser other questions tagged

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