Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

SOAP array construction with SOAP::Data::ComplexType

by takeos (Initiate)
on Nov 19, 2007 at 12:11 UTC ( [id://651647]=perlquestion: print w/replies, xml ) Need Help??

takeos has asked for the wisdom of the Perl Monks concerning the following question:

I was tired of writing a large complex data with plain SOAP::Data and was so glad to have found SOAP::Data::ComplexType, but I couldn't make a soap array with it. I tried to do exactly as the sample code does but the sample didn't even compile and I had to modify it a bit.
#!C:/perl/bin/perl -w use strict; use SOAP::Data::ComplexType; package My::Complex; use base qw(SOAP::Data::ComplexType); use constant OBJ_TYPE => 'myns:complex'; use constant OBJ_URI => 'http://my.uri.com'; use constant OBJ_FIELDS => { string_array => [ 'SOAP-ENC:Array', undef, { 'SOAP-ENC:arrayType' => 'string +' } ] }; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $data = shift; my $obj_fields = $_[1]; #second param from untouched @_ $obj_fields = defined $obj_fields && ref($obj_fields) eq 'HASH' ? +{%{+OBJ_FIELDS}, %{$obj_fields}} : OBJ_FIELDS; my $self = $class->SUPER::new($data, $obj_fields); return bless($self, $class); } my $complex = My::Complex->new({string_array => [ 'text1', 'text2', 't +ext3' ]}); print $complex->as_xml_data;
I was expecting output like
<string_array type="xsi:SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string +[3]"> <item xsi:type="xsd:string">text1</item> <item xsi:type="xsd:string">text2</item> <item xsi:type="xsd:string">text3</item> </string_array>
but all I got was three <string_array>s. I'm using SOAP::Data::ComplexType 0.044 running on ActivePerl. Please tell me what kind of mistake I've made...

Replies are listed 'Best First'.
Re: SOAP array construction with SOAP::Data::ComplexType
by erroneousBollock (Curate) on Nov 19, 2007 at 13:39 UTC
    I was tired of writing a large complex data with plain SOAP::Data and was so glad to have found SOAP::Data::ComplexType
    Stop right there. You don't have to construct SOAP::Data hierarchies by hand!. Use SOAP::WSDL (instead of SOAP::Lite), which
    • handles the namespaces for you
    • constructs outgoing complexType values (including arrays) automatically from normal perl data-structures.
    • is a subclass of SOAP::Lite.

    I simply cannot believe how many folks are doing this the hard way. It's almost like Perl-based users of SOAP hate themselves ;)

    A service method Foo expecting an array of xsd:string elements for the argument called 'Words' can be called as follows:

      $soap->Foo(Words => [qw/this is a test!/]);

    No need to hand-construct anything under SOAP::Data at all.

    -David

      Thanks for the nice advice, David. Actually I've already tried it before. Unfortunately SOAP::WSDL available via ActivePerl's Perl Package Manager is 1.20 and has a bug which causes wrong typing. And the latest version, probably 1.25, requires some ActivePerl built-in components (including SOAP::Lite) to be updated and I gave it up.

      Reading your comment, it still seems to be the best way to go though. I will try some other versions of SOAP::WSDL to see if there's any version that works on ActivePerl with minimum updates.

      Of course the correct usage of SOAP::Data::ComplexType will be also welcome.

        Unfortunately SOAP::WSDL available via ActivePerl's Perl Package Manager is 1.20 and has a bug which causes wrong typing.
        I'm using 1.20 on my production box, 1.25 on my dev box.

        I've passed arrays of strings (and arrays of other complexTypes) to services before using both versions.

        What type errors in value construction are you seeing? If there's really a problem there, perhaps you could Report a bug ?

        And the latest version, probably 1.25, requires some ActivePerl built-in components (including SOAP::Lite) to be updated and I gave it up.
        SOAP::Lite and SOAP::WSDL are both Perl-Only modules (examples aside), so just upgrade them on your dev box via CPAN, then use PPM::Make to build PPM packages for your testing/production machines. If you don't have nmake.exe (from visual studio) installed, you can get instructions here.

        SOAP::WSDL is currently undergoing a re-write (v2 series). From what I understand it will have a mostly similar interface but will be much more flexible. A (developer) release is available now for testing.

        Why don't you check if your issues are resolved with the v2 series?

        -David

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://651647]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-18 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found