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

2021Auto-generated namespaces

Expand Messages
  • Martin McFly
    Nov 7, 2002
    • 0 Attachment
      Another question:

      Is there a way to control the namespaces generated in a SOAP envelope?

      I've noticed that SOAP::Lite as a server (I used the extremely simple
      CGI server example) generates namespaces automatically to some degree.
      For example, I have a server that dispatches to a .pm with the
      following code:

      Server code:

      use SOAP::Transport::HTTP;

      $obj = SOAP::Transport::HTTP::CGI->new();
      $obj->dispatch_to('c:/Inetpub/Scripts/WSDL/Interop', 'Interop',
      'Interop::echoStructArray')
      -> handle;

      Package code:

      sub echoStructArray {
      my $self = shift;
      my $input = shift;
      $val[0] = SOAP::Data->type("SOAPStruct")->value({"varInt"=>1,
      "varFloat"=>1.1, "varString"=>"summ 1"});
      $val[1] = SOAP::Data->type("SOAPStruct")->value({"varInt"=>22,
      "varFloat"=>22.22, "varString"=>"summ 22"});
      $val[2] = SOAP::Data->type("SOAPStruct")->value({"varInt"=>333,
      "varFloat"=>333.33, "varString"=>"summ 333"});
      return SOAP::Data->name("return" => \@val);
      }

      This results in the following SOAP being returned:

      <?xml version="1.0" encoding="UTF-8"?>
      <SOAP-ENV:Envelope
      xmlns:namesp2="http://xml.apache.org/xml-soap"
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      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:Body>
      <namesp1:echoStructArrayResponse xmlns:namesp1="http://localhost/Interop">
      <return SOAP-ENC:arrayType="namesp2:SOAPStruct[3]"
      xsi:type="SOAP-ENC:Array">
      <item xsi:type="namesp2:SOAPStruct">
      <varFloat xsi:type="xsd:float">1.1</varFloat>
      <varString xsi:type="xsd:string">summ 1</varString>
      <varInt xsi:type="xsd:int">1</varInt>
      </item> etc....

      The thing that is puzzling me is where namesp2 came from. SOAP::Lite
      seems to have auto-generated this namespace of
      "xml.apache.org/xml-soap", and used it throughout the SOAP response.
      Thus, if I were writing a WSDL file, I would be forced to use
      "xml.apache.org/xml-soap" in order for my namespaces to agree.

      Similarly, if I change my .pm file to the following (all I'm doing is
      changing "SOAPStruct" to an arbitrary name "brook"):

      sub echoStructArray {
      my $self = shift;
      my $input = shift;
      $val[0] = SOAP::Data->type("brook")->value({"varInt"=>1,
      "varFloat"=>1.1, "varString"=>"summ 1"});
      $val[1] = SOAP::Data->type("brook")->value({"varInt"=>22,
      "varFloat"=>22.22, "varString"=>"summ 22"});
      $val[2] = SOAP::Data->type("brook")->value({"varInt"=>333,
      "varFloat"=>333.33, "varString"=>"summ 333"});
      return SOAP::Data->name("return" => \@val);
      }

      then the resulting SOAP response is:

      <?xml version="1.0" encoding="UTF-8"?>
      <SOAP-ENV:Envelope
      xmlns:namesp2="http://namespaces.soaplite.com/perl"
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      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:Body>
      <namesp1:echoStructArrayResponse
      xmlns:namesp1="http://localhost/Interop">
      <return SOAP-ENC:arrayType="namesp2:brook[3]" xsi:type="SOAP-ENC:Array">
      <item .... etc.

      Notice in this example that namesp2 has now changed to
      "namespaces.soaplite.com/perl"!!! How can I control what namespace is
      generated in the envelope? I'm sure there's a simple answer to this
      question, I just haven't been able to figure it out.

      Thanks

      Brook Heaton
    • Show all 5 messages in this topic