Soap::Lite and hashes

A

Alasdair Allan

Sascha said:
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.
 
T

Tad McClellan

Sascha Moellering said:
%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?
 
S

Sascha Moellering

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
 
A

Alasdair Allan

Sascha said:
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.
 
T

Tad McClellan

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


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

Sascha Moellering

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
 
S

Sascha Moellering

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
 
A

Alasdair Allan

Sascha said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top