Tuesday, April 7, 2009

3 ways to disable auto typing in SOAP::Lite client

Often SOAP::Lite will try to autotype a parameter in a request and it does it wrongly (or correctly) causing the SOAP server to fail badly (for so many reasons).

SOAP::Lite provides three ways to disable this typing. Two of the ways work at the client object level and the other does it at the SOAP::Data object level.

Client Level

The following options disable autotyping for all data items in a request:
  • autotype method. After creating a SOAP::Lite client you can disable autotyping by $soapclient->autotype(0).
    Example:
    my $soap = SOAP::Lite->uri($xmlns)->proxy($proxy)
    ->on_action( sub {"$action?type=$reqname&ns=$xmlns"} );
    $soap->autotype(0);
  • Overriding the typelookup method. You can override the typelookup to run undef/false/etc.
    Example:
    sub typelookup { return undef; }

Data object

SOAP::Data object provide a type method. This allows manually typing of the object. When this is set to an empty string no type is set nor is it autotyped by serializer. Note: undef doesn't work you must use empty string.

Here is an example:
my $range = SOAP::Data->name(
'DateRange' => \SOAP::Data->value(
SOAP::Data->name( 'StartDate' => $start )->type(''),
SOAP::Data->name( 'EndDate' => $end )->type('')
);
Someone else suggested creating SOAP::Data object directly from XML in this cause type is set to whatever value is included in the XML document.

Thanks the SOAP::Lite mailing list for the some of the ideas.

No comments:

Post a Comment