Send array data in Webservice made in Nusoap

Asked

Viewed 631 times

1

Talk to you guys, blah?

I am developing a php webservice in Soap, I am using the nuSOAP library, the tests with simple type were successful but now I need to test with complex types as bad arrays I cannot make it work, from the transmission error, already includes a command to enable this bad guy I’m doing something wrong, if anyone can help I appreciate.

Description of the error generated:

SOAP-ENV:Client: error in msg parsing:
XML error parsing SOAP payload on line 1: Space required

The structure I send and need to receive is this:

array (size=1)
  'itens' => 
    array (size=3)
      'suco' => 
        array (size=2)
          0 => int 1
          1 => string '1.90' (length=4)
      'coca cola' => 
        array (size=2)
          0 => int 1
          1 => string '4.99' (length=4)
      'miojo' => 
        array (size=2)
          0 => int 5
          1 => string '3.99' (length=4)

In the.php server file includes this command to enable complex type:

$servidor->wsdl->addComplexType(
    'onItens',
    'complexType',
    'struct',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        'itens' => 'SOAP-ENC:arrayType',
        'wsdl:arrayType' => 'xsd:string[]'
    )
);

$servidor->register(
    'WS.onLancamentos',
    array('itens'=>'tns:onItens'),
    array('retorno'=>'xsd:string'),
    $namespace,
    $namespace.'#lancamentos',
    'rpc',
    'encoded',
    'Lancamento dos itens comprados na PEGGOU'
);  

Obs: When the main array 'items' is only with one element then it works badly the number of items is undefined, so I need to configure to work with more elements.

1 answer

1

EUREKA! Problem solved.

After many tests and debugs I discovered the reason for the problem.

The problem was simply in one of the array elements.

The key 'coca cola' was giving all this error, the space between the words was what caused the error.

The solution was simply to replace the space with an underline.

Good thing this problem happened now because if it happens in the production Dae would be tense. Ufa!

Stay on the record in case someone has a problem like the one I had.

Browser other questions tagged

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