lmocsi has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm using Perl to write a web-service, but some weird thing is happening to me: if I use ->on_action() to modify the SoapAction (I need to use soapaction: "http://my.website.com/Apple/foo/getanswer"), the soap message disappears and a hash reference is returned, pointing to a small part of the soap message. What am I doing wrong?


I have an "apple_in.cgi" in the Apache cgi-bin directory
#!c:/perl/bin/perl.exe -w use Apple; use SOAP::Transport::HTTP; my $soap = SOAP::Transport::HTTP::CGI ->dispatch_with({ 'http://my.website.com/Apple/foo/getanswer' => 'A +pple' }) ->on_action(sub { join '/foo/', @_; }) ->dispatch_to('Apple') ->handle;
... and the package Apple.pm beside:
#!c:/perl/bin/perl.exe package Apple; use strict; sub getanswer{ my ($self,$soap,$other) = @_; return('Original soap message: '.$soap); } 1;
I'm testing it with the following code:
use strict; use SOAP::Lite +trace => 'debug'; $SOAP::Constants::PREFIX_ENV = "soapenv"; # Original: SOAP-ENV $SOAP::Constants::PREFIX_ENC = "soapenc"; # Original: SOAP-ENC my $ns_apple = "http://my.website.com/Apple"; my $host = "https://localhost/cgi-bin/apple_in.cgi"; # my $ns = "urn:apple"; my $cert = 'my_cert.cer'; $ENV{HTTPS_CERT_FILE} = $cert; my $soap_req = ' <apple:tree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml +ns:xsd="http://www.w3.org/2001/XMLSchema"> <mycontent code="112233"> <otherstuff value="123456" accuracy="20.0" timestamp="2013-04-06 + 23:26:16" /> </mycontent> </apple:tree> '; my $soap = SOAP::Lite ->readable(1) ->on_action( sub { join '/foo/', @_ } ) # ->uri($ns) ->proxy($host) ->autotype(0); my $som = $soap->call(SOAP::Data->name('apple:getanswer') ->attr({"xmlns:apple" => $ns_apple }) =>SOAP::Data->type('xml' => $soap_req +) ); die $som->faultstring if ($som->fault); my $res = $som->result; print "The response from the server was:\n".$res."\n";

All I get back is: "HASH(0x1e84ebc)", referring to the string: "mycontent". What am I doing wrong?

Update

A workaround could be if I change the test code (and the message sent) like this:

$soap_req =~ s/</&lt;/g; ... my $som = $soap->call(SOAP::Data->name('apple:getanswer') ->attr({"xmlns:apple" => $ns_apple }) =>SOAP::Data->name('soap') ->type('xsd:string'=> $so +ap_req) );

But I would not like to change the soap message, I just want to turn off automatic deserialization of the soap message at server side, to get access to the original soap body. How can I do that?

Replies are listed 'Best First'.
Re: Soap message turns to hash reference
by igelkott (Priest) on Apr 06, 2013 at 23:27 UTC
    HASH(0x1e84ebc)

    Looks like you just need to dereference the hash but you would probably get more information from seeing exactly what you're returning. Easiest way to do that would be to use use Data::Dumper; at the top and then print Dumper($res); at the bottom.

      I did this in Apple.pm to see, what arguments it gets (@_):
      $VAR1 = 'Apple'; $VAR2 = { 'mycontent' => { 'otherstuff' => '' } };
      Where has the content gone?
Re: Soap message turns to hash reference
by Anonymous Monk on Apr 07, 2013 at 15:14 UTC

      Unfortunately, I'm not that experienced to write a deserializer (which would simply return the soap body xml as a string). Can someone help me with this?

        Unfortunately, I'm not that experienced to write a deserializer (which would simply return the soap body xml as a string). Can someone help me with this?

        You don't need to write one, you can always access the raw http request/response