Loading ...
Sorry, an error occurred while loading the content.

Complex data structure for .NET client

Expand Messages
  • snoogen314
    Hi, I want to pass an array of hashes from a soaplite server to a .net client, using document/literal. I ve read http://www.majordojo.com/archives/000230.php
    Message 1 of 2 , May 16 4:50 AM
    • 0 Attachment
      Hi,

      I want to pass an array of hashes from a soaplite server to a .net
      client, using document/literal.

      I've read http://www.majordojo.com/archives/000230.php about how to
      generate complex data structures, but it looks like it's in
      RPC/encoded mode (with types embedded in the SOAP message)

      Is there a way to produce a doc/literal message with a custom
      serializer that would generate something like this:

      <Array>
      <ArrayItem><name>foo</name><address>123</address></ArrayItem>
      <ArrayItem><name>bar</name><address>456</address></ArrayItem>
      </Array>

      Which corresponds to this perl structure:
      [
      { name => 'foo', address => 123 },
      { name => 'bar', address => 456 },
      ]
    • snoogen314
      ... After some fiddling I found how to get my soap server to spew messages understandable by both .net AND perl. Maybe that ll help other people so here is the
      Message 2 of 2 , May 18 3:43 AM
      • 0 Attachment
        --- In soaplite@yahoogroups.com, "snoogen314" <snoogen314@y...> wrote:
        > Is there a way to produce a doc/literal message with a custom
        > serializer that would generate something like this:
        >
        > <Array>
        > <ArrayItem><name>foo</name><address>123</address></ArrayItem>
        > <ArrayItem><name>bar</name><address>456</address></ArrayItem>
        > </Array>
        >
        > Which corresponds to this perl structure:
        > [
        > { name => 'foo', address => 123 },
        > { name => 'bar', address => 456 },
        > ]

        After some fiddling I found how to get my soap server to spew
        messages understandable by both .net AND perl.

        Maybe that'll help other people so here is the code for my SOAP
        mod_perl server:

        use SOAP::Lite;
        use SOAP::Transport::HTTP;
        use My::Module; # this module contains the method 'Foo' I want to
        expose and which returns the array of hashes

        SOAP::Transport::HTTP::CGI
        -> serializer(My::Serializer->new)
        -> dispatch_to('My::Module::Foo')
        -> handle
        ;

        BEGIN {
        package My::Serializer;
        use vars qw(@ISA $URI);
        @ISA = 'SOAP::Serializer';

        sub envelope {
        my $self = shift;
        my $type = shift;
        $self->autotype(0);
        $self->use_prefix(0);

        # only modify response message for Foo()
        if ($type =~ /^response$/ && $_[0] eq 'FooResponse') {

        $_[1] = SOAP::Data->name("Array" =>
        \SOAP::Data->value(SOAP::Data->name("ArrayItem" => @{$_[1]}) )
        );
        $self->SUPER::envelope($type, @_);
        }
        1;
        }
      Your message has been successfully submitted and would be delivered to recipients shortly.