Professional Web Applications Themes

SOAP::Lite - PERL Modules

Hi, I have been playing with SOAP::Lite for a while, and generally find that it is really very useful. So the other day I came across a problem where I thought "I wonder if I can do that with SOAP?". In the past I have been writing clients and servers where the output has been typically using scalars and lists using cgi under apache. eg ----------------------------------------------------------------- #server cgi script - test.cgi: #!/usr/bin/perl -w use SOAP::Transport::HTTP; use Test_Script; SOAP::Transport::HTTP::CGI -> dispatch_to('Test_Script') -> handle; ----------------------------------------------------------- #Module Test_Script.pm package Test_Script; require Exporter; sub testsub { return(1,"Stuff","More Stuff"); } --------------------------------------------------------------------- #Typical client #!/usr/bin/perl -w ...

  1. #1

    Default SOAP::Lite

    Hi,

    I have been playing with SOAP::Lite for a while, and generally find that it
    is really very useful. So the other day I came across a problem where I
    thought "I wonder if I can do that with SOAP?".
    In the past I have been writing clients and servers where the output has
    been typically using scalars and lists using cgi under apache.
    eg
    -----------------------------------------------------------------
    #server cgi script - test.cgi:

    #!/usr/bin/perl -w

    use SOAP::Transport::HTTP;
    use Test_Script;

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

    -----------------------------------------------------------
    #Module Test_Script.pm

    package Test_Script;
    require Exporter;

    sub testsub {
    return(1,"Stuff","More Stuff");
    }
    ---------------------------------------------------------------------
    #Typical client

    #!/usr/bin/perl -w

    use SOAP::Lite;
    my $server = 'server.somewhere.com';
    $soap_response = SOAP::Lite
    -> uri('http://'.$server.'/Test_Script')
    -> proxy('http://'.$server.'/cgi-bin/test.cgi')
    -> testsub();


    $res = $soap_response->result; #$res = 1
    rc = $soap_response->paramsout; #$rc[0]="Stuff", $rc[1]="More Stuff"
    print "$res\n";
    print "$rc[0]"; #prints results.
    Great!!

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

    The question I have has probably been asked before, although I have not yet
    managed to find and
    answer.

    I have tried to return a hash. Something like this:
    -----------------------------------------------------------
    #Module Test_Script.pm

    package Test_Script;
    require Exporter;

    sub testsub {
    my %hash;
    $hash{'foo'}='bar';
    $hash{'john'}='doe';
    return(1,%hash);
    }
    ---------------------------------------------------------------------

    My client then looks like this:


    ---------------------------------------------------------------------
    #Typical client

    #!/usr/bin/perl -w

    use SOAP::Lite;
    my $server = 'server.somewhere.com';
    $soap_response = SOAP::Lite
    -> uri('http://'.$server.'/Test_Script')
    -> proxy('http://'.$server.'/cgi-bin/test.cgi')
    -> testsub();


    $res = $soap_response->result; #$res = 1
    rc = $soap_response->paramsout;
    my %hash = shift(rc);

    print "$res\n"; #works ok prints 1
    print "$hash{'john'}"; #prints nothing

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

    The result is bad. The hash does not get passed as when calling a normal
    local subroutine.

    There is some information at [url]http://guide.soaplite.com[/url] (Handling LoLs (List
    of Lists, Structs, Objects, or something else)
    but I have not been able to get the example to work if I return hashes from
    my server.

    I actually want to pass the contents of several hashes back to the client,
    but so far I have had no luck with just one!

    Is there anyone out there who can tell me where this is going wrong?

    Tx in advance.

    Nick




    Nicholas Garfield Guest

  2. #2

    Default Re: SOAP::Lite

    Nicholas Garfield wrote:
    > Hi,
    >
    > I have been playing with SOAP::Lite for a while, and generally find that it
    > is really very useful. So the other day I came across a problem where I
    > thought "I wonder if I can do that with SOAP?".
    > In the past I have been writing clients and servers where the output has
    > been typically using scalars and lists using cgi under apache.
    That's a clue ;)
    [snip]
    > The question I have has probably been asked before, although I have not yet
    > managed to find and
    > answer.
    >
    > I have tried to return a hash. Something like this:
    [snip code]
    > my %hash = shift(rc);
    doesn't shift return the array element that was shifted out? My guess is
    you're better off writing
    my %hash = rc;
    > The result is bad. The hash does not get passed as when calling a normal
    > local subroutine.
    It probably does, but you're not assigning it correctly.
    > There is some information at [url]http://guide.soaplite.com[/url] (Handling LoLs (List
    > of Lists, Structs, Objects, or something else)
    > but I have not been able to get the example to work if I return hashes from
    > my server.
    >
    > I actually want to pass the contents of several hashes back to the client,
    > but so far I have had no luck with just one!
    >
    > Is there anyone out there who can tell me where this is going wrong?
    You might get better luck passing a reference to the hash:
    return (1, \%hash);

    Then, on the client side:
    rc = $soap_response->paramsout;
    $hashref = shift rc;
    or
    %hash = %{$rc[0]};
    (but in the last case you better check whether
    ref $rc[0] eq 'HASH'
    > Tx in advance.
    >
    > Nick
    >
    HTH,
    Rhesa

    Matthias Weckman Guest

  3. #3

    Default SOAP::LITE

    I am looking to send a perl hash (%) to a java client via SOAP. I can
    seem to find the correct way to serialize this item. On the java
    side, I keep getting a apache-soap error, saying that it doesnt know
    how to de-serialize this. Any hints?
    ~Phil
    Phil Guest

  4. #4

    Default SOAP::Lite

    Probably a simple question - I'm new to SOAP and am fuzzy on the
    fundamentals. Here's my problem - in order to retrieve data from a remote
    database, I need to call a routine on the remote box, passing to it two
    params. The first is a simple string arg, but the second is a hash-type
    object with multiple fields. Can someone provide some guidance regarding
    the proper syntax for constructing such an object?

    Thanks,
    Mulligan

    [email]tristeroexciteNOCAPS.com[/email]


    M. Mulligan Guest

  5. #5

    Default Re: SOAP::Lite

    M. Mulligan <tristeroexciteremove.com> wrote:
    > Probably a simple question - I'm new to SOAP and am fuzzy on the
    > fundamentals. Here's my problem - in order to retrieve data from a
    > remote database, I need to call a routine on the remote box, passing
    > to it two params. The first is a simple string arg, but the second
    > is a hash-type object with multiple fields. Can someone provide some
    > guidance regarding the proper syntax for constructing such an object?
    >
    You will probably need to build up the structure from SOAP::Data objects
    - you might find the separate SOAP::Data::Builder useful in this regard.

    /J\
    Jonathan Stowe Guest

  6. #6

    Default SOAP::Lite

    Hi,

    new to SOAP and have some problems to get what I need.
    First some info.
    I have a webservice where I can POST a "faxNumber" and GET valid
    "EmailAddress".
    But I have no Idea how to do that with SOAP::Lite.
    The method to call is "getEmailAddressByFaxNumber".

    I tried several things, last is this:
    my $soap = SOAP::Lite
    -> uri($uri)
    -> proxy($endpoint)
    ;

    my $result = $soap->execute(
    SOAP::Data->name(
    "getEmailAddressByFaxNumber" => SOAP::Data->value(
    SOAP::Data->name("faxNumber" => '00225')
    )
    )
    );

    print $result;

    hoping someone could help me out.
    Many thanks for any help.

    Regards
    Chris

    --
    Das Informationsportal. -> http://www.bietet.info
    Für Vereine kostenloser Eintrag, Veranstaltungen kostenlos!!
    Alle Formulare/Verträge sind online als PDF nachlesbar.
    Eingetragener LinuxUser #323936 http://counter.li.org
    Christian Guest

  7. #7

    Default Re: SOAP::Lite - Solution found

    Christian Wittmer wrote:

    solution :)

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

    my $mail = SOAP::Data
    ->name('faxNumber' => '00225')
    ->type('string');
    my $result = $soap->getEmailAddressByFaxNumber($mail);

    unless ($result->fault) {
    print $result->result(), "\n";
    } else {
    print join ", \n",
    $result->faultcode,
    $result->faultstring,
    $result->faultdetail,"\n";
    }

    Thanks :)
    Chris
     

    --
    Das Informationsportal. -> http://www.bietet.info
    Für Vereine kostenloser Eintrag, Veranstaltungen kostenlos!!
    Alle Formulare/Verträge sind online als PDF nachlesbar.
    Eingetragener LinuxUser #323936 http://counter.li.org
    Christian Guest

  8. #8

    Default Re: SOAP::Lite

    Christian Wittmer wrote: 

    No great expert on either Perl or SOAP::Lite but I believe all you need
    to do is this

    my $faxNumber = '00225';
    my $email_address = SOAP::Lite
    -> uri($uri)
    -> proxy($endpoint)
    -> getEmailAddressByFaxNumber($faxNumber)
    -> result;

    john
    John Guest

Similar Threads

  1. Writing a HTML/ASP SOAP client for a SOAP::Lite destination
    By jim.long@vanderbilt.edu in forum PERL Modules
    Replies: 0
    Last Post: March 17th, 12:19 AM
  2. Replies: 1
    Last Post: November 12th, 08:31 PM
  3. SOAP::Lite : BUG somewhere
    By J Krugman in forum PERL Modules
    Replies: 0
    Last Post: January 9th, 04:18 PM
  4. SOAP::Lite HELP!
    By Mike Zupan in forum PERL Miscellaneous
    Replies: 0
    Last Post: August 23rd, 05:02 PM
  5. soap::lite and dbd::csv
    By in forum PERL Modules
    Replies: 0
    Last Post: August 6th, 02:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139