Loading ...
Sorry, an error occurred while loading the content.

Soap Server handling multiple requests in the same envelope

Expand Messages
  • atpetkov
    Hello, I am trying to design a SOAP server which should be able to process multiple requests in the same message. For example, the message looks like this:
    Message 1 of 1 , Jun 4 1:58 AM
    • 0 Attachment
      Hello,

      I am trying to design a SOAP server which should be able to process multiple requests in the same message.

      For example, the message looks like 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>


      In the message above, there are two createRecord requests and I would like my SOAP server to be able to execute them both. So far, my  implementation is able to execute only the first one. I have tried using the ForkOnAccept/ForkAfterProcessing modules from the SOAP::Transport::HTTP::Daemon package but to no avail. Here is the code that I wrote:

      #!/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 => <port_number>,
                      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/param_1")->value;
                      }
                      if ($envelope->match("//createRecord/param_2")) {
                              $param_2 = $envelope->dataof("//createRecord/param_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' => $ResponseCode)->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(@_);
          }
      }


      I am relatively new to SOAP::Lite, so I will appreciate any help that I can get.

      Thanks in advance.
    Your message has been successfully submitted and would be delivered to recipients shortly.