Posted on 2009-07-01 12:20:15-07 by tg42
accessing a web service with a <choice>

Hi all,

i am trying to access a web service which requires a data structure containing a choice -- it a Java class hierarchy on the server side, in fact.

The part in question of the wsdl looks like this:

<xs:complexType name='anweisungRequest'> <xs:sequence> <xs:choice> <xs:element ref='tns:auszahlung'/> <xs:element ref='tns:buchung'/> </xs:choice> <xs:element name='benutzer' type='tns:benutzer'/> </xs:sequence> </xs:complexType>

Now, the generated code and its comment contradict themselves, as the code for the anweisungRequest contains a choice of elements whereas its comment talks about the corresponding types. If i follow the comment and try to put an object of the respective type into the request, i get an error:

cannot use DienstType::auszahlungsAnweisung reference as value for auszahlung - DienstElement::ausz +ahlung required at test.pl line 27

If i wrap the type into the corresponding element, the construction of the request works fine, but the generated XML for the request is totally messed up:

my $element = DienstElement::auszahlung->new($anweisung->as_hash_ref()); my $request = DienstType::anweisungRequest->new(); $request->set_benutzer($benutzer); $request->set_auszahlung($element);

yields the following XML:

Anweisung: <betrag xmlns="">123.45</betrag> <datum xmlns="">2009-04-26</datum> <auszahlungsDatum xmlns="">2009-05-04</auszahlungsDatum> <programmGesteuert xmlns="">true</programmGesteuert> Element: <auszahlung xmlns="http://nowhere.net/service"> <betrag xmlns="">123.45</betrag> <datum xmlns="">2009-04-26</datum> <auszahlungsDatum xmlns="">2009-05-04</auszahlungsDatum> <programmGesteuert xmlns="">true</programmGesteuert> </auszahlung> Request: <auszahlung> <auszahlung xmlns=""> <auszahlung xmlns="">123.45</auszahlung> </auszahlung> <auszahlung xmlns=""> <auszahlung xmlns="">2009-04-26</auszahlung> </auszahlung> <auszahlung xmlns=""> <auszahlung xmlns="">2009-05-04</auszahlung> </auszahlung> <auszahlung xmlns=""> <auszahlung xmlns="">true</auszahlung> </auszahlung> </auszahlung> <benutzer xmlns=""> <id>123</id> <name xmlns="">Thomas</name> </benutzer>

Now my questions are: is there something wrong with my approach? Is this a (known) bug in SOAP::WSDL? Didn't i use the generated perl modules in the right way?

Any help appreciated,

- Thomas

Direct Responses: 11140 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.