SOAP server & client problem

S

Some1

Hello All,

I have written SOAP client send two variables "two massages" , also I
have written SOAP server accept one variable. My problem I want the
soap server accept two variables "two massages" and replay with
results.

Helle.pm file
======================
package Hello;
sub sayHello {
shift;

return "Hello Jack" if shift eq "Jack";

die "Sorry..\n";

}

1;



hello.cgi
===============================
#!/usr/bin/perl -w


use lib '/var/www/cgi-bin/Hello';
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
-> dispatch_to('Hello::(?:sayHello)')
-> handle
;
#############################
Hello.pm and hello.cgi all of them in the same folder /var/www/cgi-bin



Now the soap client script hclient.pl:
===============================
#!/usr/bin/perl -w

use SOAP::Lite;

my $name = shift;
my $lname = shift ;
print "\n\nCalling the SOAP Server to say hello\n\n";
print "The SOAP Server says: \n";
print SOAP::Lite
-> uri('urn:Hello')
-> proxy('http://homesrv/cgi-bin/hello.cgi')
-> sayHello($name,$lname)
-> result . "\n\n";

##############################END##################################3


If I run "perl hclient.pl Jack" it is working fine, but when I tried
"perl hclient.pl Jack King" it will not work... why?
by the way Jack is variable 1 and King variable 2, I want my soap
server accept all the variables.

Could you please guide me where is my mistake or how to fix it?
 
R

RedGrittyBrick

Some1 said:
Hello All,

I have written SOAP client send two variables "two massages" , also I

I think you mean "messages". Massages are something completely different :)

SOAP::Lite is more of a RPC implementation than a message-passing
implementation so it would be clearer to refer to passing arguments to
subroutine parameters or, in OO terms, to method parameters.
have written SOAP server accept one variable.

Your SOAP service includes a method that expects a single argument.
My problem I want the soap server accept two variables "two massages"

You want the method to accept two arguments?

and replay with results.

I think you mean "reply" with a single string. Replay means: to repeat
the method call with the same arguments.
Helle.pm file

You mean Hello.pm.
======================
package Hello;
sub sayHello {
shift;

return "Hello Jack" if shift eq "Jack";

This should work but I find it clearer to write
my ($class, $firstname) = @_;
etc.
die "Sorry..\n";

}

1;



hello.cgi
===============================
#!/usr/bin/perl -w


use lib '/var/www/cgi-bin/Hello';

You shouldn't need the line above.
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
-> dispatch_to('Hello::(?:sayHello)')

The line above looks odd to me. I'd have
-> dispatch_to("/var/www/cgi-bin")
-> handle
;
#############################
Hello.pm and hello.cgi all of them in the same folder /var/www/cgi-bin



Now the soap client script hclient.pl:
===============================
#!/usr/bin/perl -w

use strict;
use SOAP::Lite;

my $name = shift;
my $lname = shift ;
print "\n\nCalling the SOAP Server to say hello\n\n";
print "The SOAP Server says: \n";
print SOAP::Lite
-> uri('urn:Hello')
-> proxy('http://homesrv/cgi-bin/hello.cgi')


*Always* check for error messages!

-> on_fault(sub { my($soap, $res) = @_;
die ref $res ? $res->faultstring
: $soap->transport->status, "\n";
})
-> sayHello($name,$lname)
-> result . "\n\n";

##############################END##################################3


If I run "perl hclient.pl Jack" it is working fine, but when I tried
"perl hclient.pl Jack King" it will not work... why?


"will not work" is too vague.
The posting guidelines, which are rugularly posted to this newsgroup, say

Show the output (including the verbatim text of any messages) of
your program.

Describe how you want the output to be different from what you are
getting.

by the way Jack is variable 1 and King variable 2, I want my soap
server accept all the variables.

Could you please guide me where is my mistake or how to fix it?

You made the following mistakes:
- Not reading the posting guidelines
- Not using strict
- Not checking for errors

Your client and module run as I would expect them to.

C:> perl hello.pl Jack Plum


Calling the SOAP Server to say hello

The SOAP Server says:
Hello Jack


C:>

Since you didn't explain how the output differred from what you
expected, I can't tell if there's anything else that needs fixing.
 
S

Some1

Hi,
Thank you RedGrittyBrick.

I did C:> perl hello.pl Jack Plum
but I want the result : Hello Jack Plum

if you miss Plum, I want the soap reply with error message.

Thank a lot for your comments RedGrittyBrick.
 
J

J. Gleixner

Some1 said:
I did C:> perl hello.pl Jack Plum
but I want the result : Hello Jack Plum

It looks like you don't have a problem
with SOAP. The problem is with how to get
the arguments that are passed to your
subroutine/method.

First, write your subroutine and test it,
without using SOAP.

my $fname = $ARGV[0];
my $lname = $ARGV[1];
my $ret = sayHello( $fname, $lname );
print "sayHello returned: $ret\n";

sub sayHello {
#.. do something..
# die if something
#return something_else

}

Once sayHello() does what you want, then you should be
able to update your Hello.pm and calling it via SOAP
should work.

if you miss Plum, I want the soap reply with error message.
Hu? s/miss/pass/ ????

Possibly, something like this is what you're looking for:

sub sayHello {
my ( $self, $first, $last ) = @_;

die "Some error" unless $first eq 'Jack';
return "Hello $first $last";
}

That will return a string with a blank at the end, if $last
is undef, but that can be fixed pretty easily.
 
R

RedGrittyBrick

Some1 said:
Hi,
Thank you RedGrittyBrick.

No problem.

Please learn about top-posting and try not to do it any more :)
http://www.caliburn.nl/topposting.html

I did C:> perl hello.pl Jack Plum
but I want the result : Hello Jack Plum

if you miss Plum, I want the soap reply with error message.


Plan A.
-------

In Hello.pm change
return "Hello Jack" if shift eq "Jack";
to
return "Hello Jack Plum" if shift eq "Jack Plum";


invoke your client like this
perl hclient.pl "Jack Plum"


Plan B.
-------

In Hello.pm change
shift;
return "Hello Jack" if shift eq "Jack";
to
my ($class, $first, $last);
if (($first eq "Jack") and ($last eq "Plum")) {
return "Hello Jack Plum";
}

invoke your client like this
perl hclient.pl Jack Plum


Plan C.
 

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