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

How can you determine the name and type of rpc variables on the server side?

Expand Messages
  • ssscottmo
    Hello, I have spent alot of time and effort reading documentation, looking at source code, googling and scanning the list archives but have not been able to
    Message 1 of 3 , Dec 8, 2005
    • 0 Attachment
      Hello,

      I have spent alot of time and effort reading documentation, looking at
      source code, googling and scanning the list archives but have not been
      able to discover the answer.

      While it is clear how to establish names and types for your function
      parameters on the client side for interoperability with other soap
      apis, I have not been able to discover how to extract that information
      back from the request on the server side.

      For example, lets say I wanted to submit a job which could have any
      number of optional parameters.

      I could do something like:

      my @attrs = ();
      push @attrs, SOAP::Data->type('string')->name('user')->value('scott');
      push @attrs, SOAP::Data->type('int')->name('cpus')->value(12);
      SOAP::Lite->uri($uri)->proxy($proxy)-jobSubmit(@attrs)->result;

      I can see with a trace that the names and types are making it to the
      server:

      <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><namesp1:jobSubmit
      xmlns:namesp1="http://www.clusterresources.com/Moab/WebServices"><user
      xsi:type="xsd:string">scottmo</user><cpus
      xsi:type="xsd:int">12</cpus></namesp1:jobStart></SOAP-ENV:Body></SOAP-ENV:Envelope>

      The question is -- now how can I extract the names from the variables
      programmatically on the server side without resorting to parsing the
      body xml myself (i.e. the scottmo value has the name user and the type
      string, etc.)?

      I realize there would be ways to encode the name, values into strings,
      or use perl data structures like hashes, etc, but I believe the way I
      am attempting to use this would be the most direct way to use the SOAP
      protocol and would enable a non-perl server to respond to a perl
      client request in a straighforward manner.

      Thank you for any help you can give me on this,

      Scott Jackson
    • Duncan Cameron
      ... See the section ACCESSING HEADERS AND ENVELOPE ON SERVER SIDE in the docs for how to get hold of the SOAP envelope. You can then use the SOAP::SOM methods
      Message 2 of 3 , Dec 9, 2005
      • 0 Attachment
        At 2005-12-08, 23:34:30 you wrote:

        >Hello,
        >
        >I have spent alot of time and effort reading documentation, looking at
        >source code, googling and scanning the list archives but have not been
        >able to discover the answer.
        >
        >While it is clear how to establish names and types for your function
        >parameters on the client side for interoperability with other soap
        >apis, I have not been able to discover how to extract that information
        >back from the request on the server side.
        >
        >For example, lets say I wanted to submit a job which could have any
        >number of optional parameters.
        >
        >I could do something like:
        >
        >my @attrs = ();
        >push @attrs, SOAP::Data->type('string')->name('user')->value('scott');
        >push @attrs, SOAP::Data->type('int')->name('cpus')->value(12);
        >SOAP::Lite->uri($uri)->proxy($proxy)-jobSubmit(@attrs)->result;
        >
        >I can see with a trace that the names and types are making it to the
        >server:
        >
        ><?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
        >xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
        >xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        >xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        >xmlns:xsd="http://www.w3.org/1999/XMLSchema"
        >SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><namesp1:jobSubmit
        >xmlns:namesp1="http://www.clusterresources.com/Moab/WebServices"><user
        >xsi:type="xsd:string">scottmo</user><cpus
        >xsi:type="xsd:int">12</cpus></namesp1:jobStart></SOAP-ENV:Body></SOAP-ENV:Envelope>
        >
        >The question is -- now how can I extract the names from the variables
        >programmatically on the server side without resorting to parsing the
        >body xml myself (i.e. the scottmo value has the name user and the type
        >string, etc.)?
        >
        >I realize there would be ways to encode the name, values into strings,
        >or use perl data structures like hashes, etc, but I believe the way I
        >am attempting to use this would be the most direct way to use the SOAP
        >protocol and would enable a non-perl server to respond to a perl
        >client request in a straighforward manner.
        >
        >Thank you for any help you can give me on this,
        >
        >Scott Jackson
        >
        See the section ACCESSING HEADERS AND ENVELOPE ON SERVER SIDE in the docs for how to get hold of the SOAP envelope.
        You can then use the SOAP::SOM methods to navigate through the child elements of the jobSubmit element and pick out the name, type and value.

        Something like this might be what you need

        my $j = $som->match('/Envelope/Body/[1]');

        for (my $i = 1; my $e = $j->dataof("[$i]"); $i++) {
        print $e->name , ' ', $e->type, ' ', $e->value, "\n";
        };


        Duncan
      • Scott Jackson
        ... Duncan, Thanks for the reference. In the section you referred me to I discovered that I can get direct access to the envelope by inheriting from
        Message 3 of 3 , Dec 9, 2005
        • 0 Attachment
          > See the section ACCESSING HEADERS AND ENVELOPE ON SERVER SIDE in the docs for how to get hold of the SOAP envelope.
          > You can then use the SOAP::SOM methods to navigate through the child elements of the jobSubmit element and pick out the name, type and value.
          >
          > Something like this might be what you need
          >
          > my $j = $som->match('/Envelope/Body/[1]');
          >
          > for (my $i = 1; my $e = $j->dataof("[$i]"); $i++) {
          > print $e->name , ' ', $e->type, ' ', $e->value, "\n";
          > };

          Duncan,

          Thanks for the reference. In the section you referred me to I discovered
          that I can get direct access to the envelope by inheriting from
          SOAP::Server::Parameters. That was the key I was missing. Since all I
          really needed in this instance were the names (and not the types), it
          was a simple matter to extract the names and values with the 'method'
          call on the SOAP::SOM object popped from the extended parameters.


          package Moab::WebServices;

          use Data::Dumper;
          use Exporter;
          @ISA = qw(Exporter SOAP::Server::Parameters);
          @EXPORT = qw
          (
          &jobStart
          );

          # Start a job
          sub jobStart
          {
          my $som = pop;

          my %args = %{$som->method};
          return "jobStart received: " . Data::Dumper->Dump([\%args]);
          }

          1;

          ####

          I get a response like:

          jobStart received: $VAR1 = {
          'NAME' => 'PBS.1234.0',
          'UNAME' => 'scottmo',
          'TASKLIST' => 'node01,node02',
          'WCTIME' => '12:00:00',
          'EXEC' => '/bin/hostname'
          };

          ####


          Thank you so much for your help!

          Scott
        Your message has been successfully submitted and would be delivered to recipients shortly.