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

2028Re: Auto-generated namespaces

Expand Messages
  • Martin McFly
    Nov 8, 2002
    • 0 Attachment
      Duncan, Paul

      Thanks for the responses. My follow on question is this: my client
      code accesses a WSDL file like so:

      $soap =
      SOAP::Lite->service('http://localhost/scripts/WSDL/Interop/InteropTest.wsdl');
      ..... #initialize @val and pass it to the service
      $res = $soap->echoStructArray(\@val);

      If "brook" is defined in my WSDL, shouldn't this be sufficient? It
      appears that even if "brook" is defined and has it's own namespace,
      SOAP::Lite still generates "namespaces.soaplite.com/perl" in the
      response. So far, the only way I've been able to get my WSDL to agree
      with the returned SOAP is to put "brook" in the
      "namespaces.soaplite.com/perl" namespace.

      In a follow-on to this post, Paul said I can use the maptype method to
      specify my own namespaces. I see where I can do this for the request
      (I could just add $soap->maptype(...) into the code above), but how do
      I use maptype to change the namespace of the response? Do I need to
      rewrite my CGI server to somehow manipulate the namespaces in the SOAP
      envelope? Or can I somehow add it to my echoStructArray code?

      Thanks

      --- In soaplite@y..., Duncan Cameron <dcameron@b...> wrote:
      > On 2002-11-07 Martin McFly wrote:
      > >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.
      >
      > SOAPStruct is associated automatically with the xml.apache.org/xml-soap
      > namespace. If you don't want that namespace then don't use
      > type('SOAPStruct') or type it as something else. What is appropriate
      > depends on your destination system.
      >
      > >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.
      >
      > Now you have specified a type of 'brook' without any definition of
      > what that type is. SOAP::Lite has to put it in a namespace so has
      > put it in its own one.
      >
      > If you're confused by this then you probably need to clarify what
      > your destination system is expecting.
      >
      > Regards,
      > Duncan Cameron
    • Show all 5 messages in this topic