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

named arrays of structs

Expand Messages
  • Peter Sykora
    Hello, I created a SOAP Server with gSOAP that expects named arrays of structs. Now I want to access this server using a soaplite client. So I create a named
    Message 1 of 3 , Dec 1, 2003
    • 0 Attachment
      Hello,

      I created a SOAP Server with gSOAP that expects named arrays of
      structs. Now I want to access this server using a soaplite client. So
      I create a named array of hashes using something like this:

      SOAP::Data->type('DataArray')->name('DataArray' => \@data_array);

      It works fine under windows where the resulting SOAP message sent to
      the server looks something like:

      <?xml version="1.0" encoding="UTF-8"?>
      <SOAP-ENV:Envelope
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema">
      <SOAP-ENV:Body>
      <namesp4:proj_array xmlns:namesp4="urn:project4-wrapper">
      <ParameterArray SOAP-ENC:arrayType="xsd:string[6]"
      xsi:type="namesp4:ParameterArray">
      <c-gensym32 xsi:type="xsd:string">+proj=laea</c-gensym32>
      <c-gensym32 xsi:type="xsd:string">+a=6384287.0</c-gensym32>
      <c-gensym32 xsi:type="xsd:string">+lon_0=13d20E</c-gensym32>
      <c-gensym32 xsi:type="xsd:string">+lat_0=47d30N</c-gensym32>
      <c-gensym32 xsi:type="xsd:string">+x_0=400000</c-gensym32>
      <c-gensym32 xsi:type="xsd:string">+y_0=400000</c-gensym32>
      </ParameterArray>
      <DataArray SOAP-ENC:arrayType="DataPoint[2]"
      xsi:type="namesp4:DataArray">
      <DataPoint xsi:type="namesp4:DataPoint">
      <x xsi:type="xsd:double">397485.92771528574</x>
      <y xsi:type="xsd:double">388857.85752570926</y>
      </DataPoint>
      <DataPoint xsi:type="namesp4:DataPoint">
      <x xsi:type="xsd:double">411691.04325841984</x>
      <y xsi:type="xsd:double">431557.77594223403</y>
      </DataPoint>
      </DataArray>
      <c-gensym36 xsi:type="xsd:int">1</c-gensym36>
      </namesp4:proj_array>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>

      Now I use the exact same client under Unix but there the client
      produces a different SOAP message:

      <?xml version="1.0" encoding="UTF-8"?>
      <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:namesp6="http://namespaces.soaplite.com/perl"
      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:Body>
      <namesp5:proj_array xmlns:namesp5="urn:project4-wrapper">
      <ParameterArray SOAP-ENC:arrayType="xsd:string[6]"
      xsi:type="namesp6:ParameterArray">
      <item xsi:type="xsd:string">+proj=laea</item>
      <item xsi:type="xsd:string">+a=6384287.0</item>
      <item xsi:type="xsd:string">+lon_0=13d20E</item>
      <item xsi:type="xsd:string">+lat_0=47d30N</item>
      <item xsi:type="xsd:string">+x_0=400000</item>
      <item xsi:type="xsd:string">+y_0=400000</item>
      </ParameterArray>
      <DataArray SOAP-ENC:arrayType="namesp6:DataPoint[2]"
      xsi:type="namesp6:DataArray">
      <DataPoint xsi:type="namesp6:DataPoint">
      <x xsi:type="xsd:double">13.3</x>
      <y xsi:type="xsd:double">47.4</y>
      </DataPoint>
      <DataPoint xsi:type="namesp6:DataPoint">
      <x xsi:type="xsd:double">13.48948</x>
      <y xsi:type="xsd:double">47.78311</y>
      </DataPoint>
      </DataArray>
      </namesp5:proj_array>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>

      Now the server fails with the error message: Datatype
      'namesp6:DataArray' mismatch in element 'DataArray'()

      The difference between the two messages is the type definition of the
      DataArray (SOAP-ENC:arrayType="DataPoint[2]" and
      SOAP-ENC:arrayType="namesp6:DataPoint[2]"). Does anybody know where
      this difference comes from or how I can define the arrayType
      explicitly to avoid that problem?

      Thanks for any hints
      Peter
    • jpeyser
      Peter, Any attribute can be overridden with the attr method. SOAP::Data- type( DataArray )- name( DataArray = @data_array) - attr({ SOAP-ENC:arrayType =
      Message 2 of 3 , Dec 1, 2003
      • 0 Attachment
        Peter,
        Any attribute can be overridden with the attr method.

        SOAP::Data->type('DataArray')->name('DataArray' => \@data_array)
        ->attr({'SOAP-ENC:arrayType' => 'DataPoint[2]'});

        (You might be better off redefining SOAP::Serializer::maptypetouri)

        Jonathan

        --- In soaplite@yahoogroups.com, "Peter Sykora" <peter_sykora@g...>
        wrote:
        > Hello,
        >
        > I created a SOAP Server with gSOAP that expects named arrays of
        > structs. Now I want to access this server using a soaplite client.
      • jpeyser
        After further study, I see that the difference between the two xml s is not the namespace prefixes, but the namespaces themselves. In the first xml (generated
        Message 3 of 3 , Dec 2, 2003
        • 0 Attachment
          After further study, I see that the difference between the two xml's
          is not the namespace prefixes, but the namespaces themselves. In the
          first xml (generated by Windows SOAP?) all the objects have the same
          prefix (namesp4), thus the same namespace. In the second xml
          (generated by SOAP::Lite), each object is assigned a different
          namespace prefix (with the default namespace of
          http://namepspaces.soaplite.com/perl)

          If you want all objects to use a certain namespace, use the maptype
          method.

          my $soap = SOAP::Lite->new();
          $soap->serializer->maptype->{DataPoint} = 'urn:project4-wrapper';
          $soap->serializer->maptype->{DataArray} = 'urn:project4-wrapper';

          $soap
          -> uri
          -> proxy
          .
          .
          .

          The namespace assignments will be inserted into the envelope header.

          Jonathan

          --- In soaplite@yahoogroups.com, "Peter Sykora" <peter_sykora@g...>
          wrote:
          > Hello,
          >
          > I created a SOAP Server with gSOAP that expects named arrays of
          > structs. Now I want to access this server using a soaplite client.
          So
          > I create a named array of hashes using something like this:
          >
          > SOAP::Data->type('DataArray')->name('DataArray' => \@data_array);
          >
          > It works fine under windows where the resulting SOAP message sent to
          > the server looks something like:
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.