I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-06-01 23:24:04.752657-07 by lom42
wsdl2perl and arrays

Hello,


I am using generated classes from wsdl2perl, which after the soap call should return (between other things) an array of objects. My issue is that whatever I do I cannot access more than one element in this array, whereas I can see that the xml, both generated and received, are correct.


The wsdl is at https://www.wdl.com/api/ordering.asmx?WSDL and my issue is with the ArrayOfOrderPlacedLine element. I would like to access all the OrderPlacedLine inside.

All classes have been generated in the WDL tree.


The code is:


my $interface = WDL::Interfaces::ordering::orderingSoap->new(); my $confirmation = $interface->PlaceOrder({ request => { IsTest => 1, Email => 'tartiflette@cheese.com', Password => 'tartiflette', PurchaseOrderRef => 'ref_42', Lines => [{CatalogueNo => 42, Qty => 5}, {CatalogueNo => 43, Qty => 6}] } }); # $results isa(WDL::Types::OrderConfirmation) my $results = $confirmation->get_PlaceOrderResult(); # $placedLines isa(WDL::Types::ArrayOfOrderPlacedLine) my $placedLines = $results->get_PlacedLines();

From there, ref($placedLines ) eq WDL::Types::ArrayOfOrderPlacedLine, scalar(@$placedLines) == 1, $placedLines->[0] references the same object as $placedLines, $placedLines->[1] is undef. This is where I would expect to access all returned lines.


The only method I can call on this object (according to doc and generated source) are {get|set}_OrderPlacedLine. This is not an iterator, I checked this, and $placedLines->get_OrderPlacedLine->get_Qty() gives me the expected result for the 1st line only.


The returned xml looks fine to me:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/en +velope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/X +MLSchema"> <soap:Body> <PlaceOrderResponse xmlns="http://tempuri.org/"> <PlaceOrderResult> <PlacedLines> <OrderPlacedLine> <CatalogueNo>42</CatalogueNo> <Qty>5</Qty> <ItemPrice>2.62</ItemPrice> </OrderPlacedLine> <OrderPlacedLine> <CatalogueNo>43</CatalogueNo> <Qty>6</Qty> <ItemPrice>2.58</ItemPrice> </OrderPlacedLine> </PlacedLines> <RejectedLines/> <PurchaseOrderRef>ref_42</PurchaseOrderRef> <OrderRef>TESTNOTCREATED</OrderRef> </PlaceOrderResult> </PlaceOrderResponse> </soap:Body> </soap:Envelope>

Would any of you know what I have done wrong here, and how I can access all the lines of the returning xml? Any help would be greatly appreciated.

Direct Responses: 12741 | 12743 | Write a response
Posted on 2010-06-03 08:50:35.134344-07 by mkutter in response to 12737
Re: wsdl2perl and arrays
Hi,
which version are you using?
Martin
Direct Responses: 12742 | Write a response
Posted on 2010-06-03 10:14:08.8351-07 by lom42 in response to 12741
Re: wsdl2perl and arrays

Hi,

Sorry, I should have mentioned that. I use the last non-dev version, built directly from CPAN a few days ago: SOAP-WSDL-2.00.10.

Thanks,

Guillaume

Direct Responses: Write a response
Posted on 2010-06-03 11:14:16.465892-07 by mkutter in response to 12737
Re: wsdl2perl and arrays
Hi,
this may be due to the way SOAP::WSDL based objects handle array conversion. Try to access the result as @{ $value }. See http://search.cpan.org/~mkutter/SOAP-WSDL-2.00.10/lib/SOAP/WSDL/XSD/Typelib/Builtin.pm#OVERLOADED_OPERATORS for details.
Martin
Direct Responses: 12746 | Write a response
Posted on 2010-06-04 01:16:15.170869-07 by lom42 in response to 12743
Re: wsdl2perl and arrays

Hi,

Thanks for the link, It pointed me to the right answer.


As it turned out, it was my mistake: having tryied different things I left wrong data in the SOAP call. The page you pointed me helped me debug that.


Sorry for the hassle and thanks for the help, it definitely saved me.


Guillaume

Direct Responses: Write a response