Soap::Lite and hashes

Discussion in 'Perl Misc' started by Alasdair Allan, Jul 22, 2003.

  1. Sascha Moellering wrote:
    > I`ve a Hashtable containing several Hashtables and I want to send this to
    > a server using SOAP::Lite, but the problem is that I don`t know how to
    > serialize and deserialize the data...


    Well you can just do it this way...

    Sending,

    my $soap = new SOAP::Lite();
    $soap->uri( $urn );
    $soap->proxy( $endpoint );

    eval { $result = $soap->method( %hash ); };
    if ( $@ ) {
    print "Error: $@";
    exit;
    }

    unless ( $result->fault() ) {
    print "Result: " . $result->result() . "\n";
    } else {
    print "Fault: " . $result->faultstring() . "\n";
    }

    and then recieving,

    sub method {
    my $self = shift;
    my %hash = @_;

    foreach my $key ( sort keys % hash ) {
    print "$key = $hash{$key}\n";
    }

    return SOAP::Data->name('return', 'ACK')->type('xsd:string');
    }

    I'm not sure why you're trying to concern yourself with serialisaton and
    deserialisation? Are you calling an RPC style service, or a document
    literal style service? If its an RPC style serice the above code will
    do what you want, and SOAP::Lite will take care of the messy details for
    you...

    Al.
     
    Alasdair Allan, Jul 22, 2003
    #1
    1. Advertising

  2. Sascha Moellering <> wrote:

    > %hash = {`1` => {id => `sdf`, user => `asd`}, `2` => {id => `wer`, user =>
    > `aqwe`}}



    That is not Perl code.

    If it was intended to be, then it has missed the mark with _multiple_
    syntax errors.

    If you expect people to help you the least you can do is ensure
    that the question is accurate.


    Have you seen the Posting Guidelines that are posted here frequently?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 22, 2003
    #2
    1. Advertising

  3. Hi,

    I`ve a Hashtable containing several Hashtables and I want to send this to a
    server using SOAP::Lite, but the problem is that I don`t know how to
    serialize and deserialize the data. Example Data:

    %hash = {`1` => {id => `sdf`, user => `asd`}, `2` => {id => `wer`, user =>
    `aqwe`}}


    Thank you,

    Sascha
     
    Sascha Moellering, Jul 22, 2003
    #3
  4. Sascha Moellering wrote:
    > Alasdair Allan wrote:
    > > I'm not sure why you're trying to concern yourself with serialisaton
    > > and deserialisation...

    >
    > I tried the following, but there is still an error...


    You've got some errors, try the following,

    --- Client.pl ---

    use SOAP::Lite;

    my $urn = "urn:/Demo";
    my $endpoint = "http://127.0.0.1:8000";

    my $soap = new SOAP::Lite();
    $soap->uri( $urn );
    $soap->proxy( $endpoint );

    my %hash = ( "one" => "1", "two" => "2" );

    eval {
    my $result = $soap->soapTest( %hash );
    };
    if ( $@ ) {
    print "Error: $@";
    exit;
    }

    -----------------

    and the server,

    --- Server.pl ---


    use SOAP::Transport::HTTP;

    my $daemon = new SOAP::Transport::HTTP::Daemon(
    LocalHost => '127.0.0.1',
    LocalPort => 8000 );

    $daemon->dispatch_to('Demo');;
    $daemon->handle();

    package Demo;

    sub soapTest
    {
    my $self = shift;
    my %hash = @_;

    my $str;
    foreach my $key(keys %hash){
    print "$key = $hash{$key}\n";
    }

    }

    -----------------

    I'm using SOAP::Transport::HTTP::Daemon as I didn't have a handy server
    around to use the CGI module as you did in your example. The main problem
    you had was that you were trying to send a reference to a hash instead of
    a hash...

    Al.
     
    Alasdair Allan, Jul 22, 2003
    #4
  5. Alasdair Allan <> wrote:
    > Tad McClellan wrote:
    >> Sascha Moellering wrote:


    >> > %hash = {`1` => {id => `sdf`, user => `asd`},
    >> > `2` => {id => `wer`, user => `aqw`}}

    ^ ^ ^ ^ ^ ^
    ^ ^ ^ ^ ^ ^

    > my %hash = ( '1' => { 'id' => 'sdf', 'user' => 'asd' },
    > '2' => { 'id' => 'wer', 'user' => 'aqw' } );



    You changed 14 characters there, that's a lot of errors.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 22, 2003
    #5
  6. Alasdair Allan wrote:
    ....

    > I'm not sure why you're trying to concern yourself with serialisaton and
    > deserialisation? Are you calling an RPC style service, or a document
    > literal style service? If its an RPC style serice the above code will
    > do what you want, and SOAP::Lite will take care of the messy details for
    > you...
    >


    Hi,

    I tried the following, but there is still an error:


    Client:

    my $soap = new SOAP::Lite();
    $soap->uri( $urn );
    $soap->proxy( $endpoint );

    my %hash = {"one" => "1", "two" => "2"};

    eval {
    my $result = $soap->soapTest( %hash );
    };
    if ( $@ ) {
    print "Error: $@";
    exit;
    }


    Server:

    SOAP::Transport::HTTP::CGI
    -> dispatch_to('Demo')
    -> handle;

    package Demo;

    sub soapTest
    {
    my $self = shift;
    my (%hash) = @_;

    my $str;
    foreach my $key(keys %hash){
    print "$key = $hash{$key}\n";
    #$str = $str.$key." => ".($hash{$key})."\n";
    }

    #return $str;
    }


    Error:

    [Wed Jul 23 01:03:20 2003] [error] [client 127.0.0.1] malformed header from
    script. Bad header=HASH(0x807e1c0) = : server.cgi


    The soap-body looks a bit strange:
    ....
    <SOAP-ENV:Body>
    <namesp1:soapTest xmlns:namesp1="http://localhost/Demo">
    <c-gensym3 xsi:type="xsd:string">HASH(0x807e1c0)</c-gensym3>
    <c-gensym5 xsi:null="1"/>
    </namesp1:soapTest>
    </SOAP-ENV:Body>
    ....


    Thank you,

    Sascha
     
    Sascha Moellering, Jul 23, 2003
    #6
  7. Alasdair Allan wrote:


    > I'm using SOAP::Transport::HTTP::Daemon as I didn't have a handy server
    > around to use the CGI module as you did in your example. The main problem
    > you had was that you were trying to send a reference to a hash instead of
    > a hash...
    >


    Hi,

    I think, I can't use this solution, because I have to send the data using
    SSL. I even tried to dereference the hash, but that does not work:

    <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
    <faultcode xsi:type="xsd:string">SOAP-ENV:Server</faultcode>
    <faultstring xsi:type="xsd:string">Can't use string ("1") as a HASH ref
    while "strict refs" in use at server.cgi line 16. </faultstring>
    </SOAP-ENV:Fault>
    </SOAP-ENV:Body>


    Thank you,

    Sascha
     
    Sascha Moellering, Jul 23, 2003
    #7
  8. Sascha Moellering wrote:
    > Alasdair Allan wrote:
    > > I'm using SOAP::Transport::HTTP::Daemon as I didn't have a handy
    > > server around to use the CGI module as you did in your example....

    >
    > I think, I can't use this solution, because I have to send the data using
    > SSL...


    I don't understand, what does SSL have to do with it? the Daemon module
    doesn't support it, but just use the CGI or Apache module instead, its
    just a direct swap in the server code.

    > I even tried to dereference the hash, but that does not work:


    Well, no, obviously...

    Al.
     
    Alasdair Allan, Jul 23, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Holness

    Hashes of Hashes via subs

    Ben Holness, Oct 5, 2003, in forum: Perl
    Replies:
    8
    Views:
    568
    Ben Holness
    Oct 8, 2003
  2. Aaron Brady

    SQL, lite lite lite

    Aaron Brady, Dec 29, 2008, in forum: Python
    Replies:
    15
    Views:
    761
    Aaron Brady
    Jan 1, 2009
  3. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    216
  4. Replies:
    3
    Views:
    209
  5. droesler
    Replies:
    2
    Views:
    511
    droesler
    Aug 31, 2010
Loading...

Share This Page