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

Hello,

I'm trying to design a SOAP server using SOAP::Lite (SOAP::Transport::HTTP::Daemon) which should be able to process several requests in the same envelope/message.

The input message looks similar to this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <m:createRecord xmlns:m="ns://TestSoapServer/SoapServer"> <m:param_1>value_1</m:param_1> <m:param_2>value_2</m:param_2> </m:createRecord> <m:createRecord xmlns:m="ns://TestSoapServer/SoapServer"> <m:param_1>value_3</m:param_1> <m:param_2>value_4</m:param_2> </m:createRecord> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

If the message above is received, then both createRecord requests must be executed. However, my current implementation only executes the first one. I have tried using the ForkOnAccept/ForkAfterProcessing modules but to no avail.

Here is the code I've written:

#!/usr/bin/perl use strict; use warnings; #use SOAP::Transport::HTTP; eval { require SOAP::Transport::HTTP::Daemon::ForkOnAccept } or die << +EOW; $@ WARNING: module for Daemon::ForkOnAccept is not installed by default +. It's in examples/SOAP/Transport/HTTP/ directory you can install it yourself. Feel free to modify it. It's just an example. EOW $SIG{PIPE} = $SIG{INT} = 'IGNORE'; # don't want to die on 'Broken pipe +' or Ctrl-C $SIG{CHLD} = 'IGNORE'; my $Server = SOAP::Transport::HTTP::Daemon::ForkOnAccept -> new (LocalHost => <hostname>, LocalPort => <portnumber>, Listen => 10, Reuse => 1, Timeout => 10) -> serializer(MySerializer->new) -> dispatch_to('SoapServer'); $Server->handle; BEGIN { package SoapServer; use vars qw(@ISA); @ISA = qw(SOAP::Server::Parameters); use SOAP::Lite; sub createRecord { print "createRecord request received...\n"; shift; my $envelope = pop; my $param_1; my $param_2; if ($envelope->match("//createRecord/param_1")) { $param_1 = $envelope->dataof("//createRecord/p +aram_1")->value; } if ($envelope->match("//createRecord/param_2")) { $param_2 = $envelope->dataof("//createRecord/p +aram_2")->value; } print "param_1=$param_1, param_2=$param_2\n"; my $ResponseCode = 0; my $ResponseMessage = "OK"; SOAP::Data->name("m:Response" => SOAP::Data->value( SOAP::Data->name('m:responseCode' => $Respo +nseCode)->type("positiveInteger"), SOAP::Data->name('m:responseCodeDescription' = +> $ResponseMessage)->type("string"))); } } BEGIN { package MySerializer; @MySerializer::ISA = 'SOAP::Serializer'; sub envelope { if( $_[1] =~ /^(?:method|response)$/ ) { $_[2] = SOAP::Data->name("Response")->prefix('m')->uri('ns +://TestSoapServer/SoapServer'); } shift->SUPER::envelope(@_); } }

If I send the SOAP message shown above, I expect the following output:

createRecord request received... param_1=value_1, param_2=value_2 createRecord request received... param_1=value_3, param_2=value_4

Instead, I just get:

createRecord request received... param_1=value_1, param_2=value_2
I am relatively new to SOAP::Lite and SOAP in general, so any help will be much appreciated. Thanks in advance.

Replies are listed 'Best First'.
Re: SOAP::Lite server handling multiple requests in the same envelope
by Anonymous Monk on Jun 04, 2012 at 11:58 UTC

    I think you need to share the client for this server

      I do not know what client will be used to access it, so the server should not be tailored to a specific client. I am currently using soapUI to send sample requests like the one I posted above.

        I do not know what client will be used to access it, so the server should not be tailored to a specific client. I am currently using soapUI to send sample requests like the one I posted above.

        For some reason you've chosen SOAP::Lite, I think the first thing you should figure out is how to send your desired request using a SOAP::Lite client -- I don't think you'll be able to figure it out on your own :)

        Its not like I've seen tons of SOAP, but from what dozen I've seen, they all pretty much stick to a single child for Body -- deviating from this will create work for everyone who wants to connect to your server -- if you've got WSDL I'd like to see it