Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: SOAP::Lite server - changing method name in response

by Anonymous Monk
on Aug 24, 2011 at 14:38 UTC ( #922126=note: print w/ replies, xml ) Need Help??


in reply to SOAP::Lite server - changing method name in response

I tried to use the guide on http://cookbook.soaplite.com/#changing%20method%20name%20in%20response , but it doesn't seem to work, I guess it's not applicable on what I'm doing.

The code you posted doesn't show any code from the guide, or a client.

It works for me, goes from

<product_info_requestResponse xmlns="http://127.0.0.1/MyModule" xsi:ni +l="true"/>
to
<product_info_request xmlns="http://127.0.0.1/MyModule">

#!/usr/bin/perl -- #~ 2011-08-24-07:25:06PDT by Anonymous Monk #~ perltidy -csc -otr -opr -ce -nibc -i=4 use strict; use warnings; use Proc::Background; Main( @ARGV ); exit( 0 ); sub Main { my( $cos ) = @_; if( $cos ){ GoServer() if $cos == 1; GoClient() if $cos == 2; } else { GoGo(); } } sub GoGo { my $serv = Proc::Background->new( $^X, __FILE__, 1 => 'GoServer' ) +; sleep 1; my $cli = Proc::Background->new( $^X, __FILE__, 2 => qw'Go Client' + ); sleep 1; $cli->die; $serv->die; } sub GoServer { require MyModule; require SOAP::Lite; require SOAP::Transport::HTTP; my $daemon = SOAP::Transport::HTTP::Daemon->new( LocalAddr => '127.0.0.1', LocalPort => 1203, Reuse => 1 ) #~ ->serializer( MySerializer->new ) # WORKS ->dispatch_to('MyModule'); print "SOAP server started at ", $daemon->url, "\n"; $daemon->handle; } sub GoClient { require SOAP::Lite; my $soap = SOAP::Lite -> uri('http://127.0.0.1/MyModule') -> proxy('http://127.0.0.1:1203'); $soap->transport->add_handler("request_send", \&pp_dump ); $soap->transport->add_handler("response_done", \&pp_dump ); $soap->product_info_request("one","two","three"); } sub pp { use XML::Twig; open my($fh), '>', \my $str; no warnings 'newline'; XML::Twig->new(qw! pretty_print record !)->xparse(@_)->print( $fh +); return $str; } sub pp_dump { my $content = $_[0]->content(''); $_[0]->content( pp($content) ); print $_[0]->as_string,"\n"; return; } BEGIN { package MyModule; use strict; sub product_info_request { my ($self,@args) = @_; return (SOAP::Header->name(prod_no => $args[1])->type('string' +)); } BEGIN { $INC{'MyModule.pm'} = __FILE__; } 1; } BEGIN { package MySerializer; @MySerializer::ISA = 'SOAP::Serializer'; sub envelope { $_[2] =~ s/Response$// if $_[1] =~ /^(?:method|response)$/; shift->SUPER::envelope(@_); } BEGIN { $INC{'MySerializer.pm'} = __FILE__; } 1; } __END__


Comment on Re: SOAP::Lite server - changing method name in response
Select or Download Code
Re^2: SOAP::Lite server - changing method name in response
by DreamT (Pilgrim) on Aug 24, 2011 at 14:57 UTC
    <quote>The code you posted doesn't show any code from the guide, or a client. </quote> - I intentionally left out the guide code since I didn't get it to work, to "start from scratch" so to speak. Regarding the client, I left it out since I didn't think it was needed - I know how the data should look like. But I guess it should've been included for the possibility to recreate the problem.

    I tried to add
    BEGIN { package MySerializer; @MySerializer::ISA = 'SOAP::Serializer'; sub envelope { $_[2] =~ s/Response$// if $_[1] =~ /^(?:method|response)$/; shift->SUPER::envelope(@_); }

    in the end of MyModule, but it doesn't seem to do anything. Maybe because I'm not using the Daemon approach, but rather the "cgi-server" approach?

    My client code:
    #!/usr/bin/perl use SOAP::Lite +trace => 'debug'; use Data::Dumper; $HOST = "http://path/to/server.pl"; $NS = "urn:MyModule"; $PHRASE = shift; # read from the command line my $soap = SOAP::Lite ->readable(1) ->uri($NS) ->proxy($HOST); my $som = $soap->product_info_request( SOAP::Data->name("version" + => "1.0"), SOAP::Data->name("prod_no" + => "$PHRASE") ); $res = $som->result; print Dumper($som);

      in the end of MyModule, but it doesn't seem to do anything. Maybe because I'm not using the Daemon approach, but rather the "cgi-server" approach? My client code:

      Um, I alrady went through the trouble of posting a complete, runnable, self contained, working example

      Copy and paste all the appropriate bits into your program

        I appreciate your effort.:) I ran it (in two instances of course, one server and one client) and got the following result:<bt>
        <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc +oding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http:/ +/www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSche +ma-instance"> <soap:Header> <prod_no xsi:type="xsd:string">two</prod_no> </soap:Header> <soap:Body> <product_info_requestResponse xmlns="http://127.0.0.1/MyModule" xs +i:nil="true"/> </soap:Body> </soap:Envelope>

        Also, it may be a problem for me using Proc::Background, since the environment that this is going to be used in is quite hard to install new perl modules. But that's a minor.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://922126]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-07-12 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls