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

Expand Messages
  • gnawed
    I have a question about passing ComplexTypes to a server. I have the following ComplexType defined: Types:
    Message 1 of 1 , Sep 15 9:03 PM
    • 0 Attachment
      I have a question about passing ComplexTypes to a server.
      I have the following ComplexType defined:

      Types:
      <xsd:complexType name="Fullname">
      <xsd:all>
      <xsd:element maxOccurs="1" minOccurs="0" name="firstname"
      type="xsd:string"/>
      <xsd:element maxOccurs="1" minOccurs="0" name="lastname"
      type="xsd:string"/>
      </xsd:all>
      </xsd:complexType>

      Messages:
      <message name="ComplexRequest">
      <part name="inParam" type="tns:Fullname" />
      </message>


      This gets passed into a simple method called setComplex() which
      returns the Dumper string of the input:

      Server (uses Apache::SOAP):
      package NTF::API::Test;

      use Data::Dumper;
      use base qw(SOAP::Server::Parameters);
      use SOAP::Lite;
      use strict;

      sub setComplex {
      my $self = shift;
      my @args = SOAP::Server::Parameters::byName([qw(inParam)], @_);

      return Dumper(\@args);
      }


      When I call it with following client code:

      use strict;
      use Data::Dumper;
      use SOAP::Lite +trace=>"debug";

      my $s = SOAP::Lite->service("http://someurl.com/Test.wsdl");

      my $q = $s->getComplex(
      SOAP::Data->name( 'inParam' )
      ->value(
      SOAP::Data->name(firstname=>'John')->type
      ('string'),
      SOAP::Data->name(lastname=>'Doe')->type
      ('string'),
      )->type('tns:Fullname')->attr
      ({'xmlns:tns'=>'urn:/NTF/API/Test'})
      );
      print "Received: ", Dumper($q);


      I see the following request body:

      <SOAP-ENV:Body>
      <namesp1:getComplex xmlns:namesp1="urn:/NTF/API/Test">
      <firstname xsi:type="xsd:string">John</firstname>
      <lastname xsi:type="xsd:string">Doe</lastname>
      </namesp1:getComplex>
      </SOAP-ENV:Body>


      The 'inParam/Fullname' tag is missing. As a newbie to WSDL, is this
      the correct structure of the request given the type defined in the
      WSDL?

      I tried passing in the objects as refs, which came closer:

      my $q = $s->getComplex(
      SOAP::Data->name( 'inParam' )
      ->value(
      \SOAP::Data->name(firstname=>'John')->type
      ('string'),
      \SOAP::Data->name(lastname=>'Doe')->type
      ('string'),
      )->type('tns:Fullname')->attr
      ({'xmlns:tns'=>'urn:/NTF/API/Test'})
      );

      <SOAP-ENV:Body>
      <namesp1:getComplex xmlns:namesp1="urn:/NTF/API/Test">
      <inParam xsi:type="tns:Fullname" xmlns:tns="urn:/NTF/API/Test">
      <firstname xsi:type="xsd:string">John</firstname>
      </inParam>
      <inParam xsi:type="tns:Fullname" xmlns:tns="urn:/NTF/API/Test">
      <lastname xsi:type="xsd:string">Doe</lastname>
      </inParam>
      </namesp1:getComplex>
      </SOAP-ENV:Body>


      except now there are two <inParam> tags.

      I also tried it as a list:

      my $q = $s->getComplex(
      SOAP::Data->name( 'inParam' )
      ->value( [
      SOAP::Data->name(firstname=>'John')->type
      ('string'),
      SOAP::Data->name(lastname=>'Doe')->type
      ('string'),
      ]
      )->type('tns:Fullname')->attr
      ({'xmlns:tns'=>'urn:/NTF/API/Test'})
      );


      Now its very close, except that <inParam> is an array (or is it?):

      <SOAP-ENV:Body>
      <namesp1:getComplex xmlns:namesp1="urn:/NTF/API/Test">
      <inParam xsi:type="tns:Fullname" xmlns:tns="urn:/NTF/API/Test"
      SOAP-ENC:arrayType="xsd:string[2]">
      <firstname xsi:type="xsd:string">John</firstname>
      <lastname xsi:type="xsd:string">Doe</lastname>
      </inParam>
      </namesp1:getComplex>
      </SOAP-ENV:Body>


      How do I get SOAP::Lite to construct the proper XML?

      <SOAP-ENV:Body>
      <namesp1:getComplex xmlns:namesp1="urn:/NTF/API/Test">
      <inParam xsi:type="tns:Fullname" xmlns:tns="urn:/NTF/API/Test">
      <firstname xsi:type="xsd:string">John</firstname>
      <lastname xsi:type="xsd:string">Doe</lastname>
      </inParam>
      </namesp1:getComplex>
      </SOAP-ENV:Body>


      I actually want to return this ComplexType from the server, but I
      assume the construction of the data structure would be the same
      whether for a client or a server.


      Also, in order to parse this ComplexType, do I need to write my own
      deserializer?
    Your message has been successfully submitted and would be delivered to recipients shortly.