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

RE: replace namesp1 from method call?

Expand Messages
  • Byrne Reese
    Last week I showed how to override the root element of a request, but did not show a way to do the same thing for the root element of a response. So, read on
    Message 1 of 4 , Apr 30, 2003
      Last week I showed how to override the root element of a request, but did
      not show a way to do the same thing for the root element of a response. So,
      read on if you would like to know how to modify the response's namespace,
      namespace prefix, encoding style, etc. It is not very intuitive, or pretty
      for that matter, but at least it is relatively simple.

      The key in overriding properties of the root element of the response is to
      write a customer serializer. What is a serializer? A serializer converts
      abstract data into a format that can more easily be transmitted between
      endpoints. In this case, a serializer converts scalar and complex data into
      XML. By writing our own serializer we can tell SOAP::Lite how to construct
      the XML representing the response.

      To create a custom serializer, you need to know a little bit about Perl OOP
      (Object Oriented Programing) and inheritence. The following code block shows
      a custom serializer which inherits all properties and behavior from the
      default SOAP::Lite Serializer, but overrides one of its methods/subroutines
      with its own:

      package MySerializer;
      @MySerializer::ISA = 'SOAP::Serializer';
      sub envelope {
      $_[2] =
      SOAP::Data->name($_[2])->prefix('temp')->uri('urn:TemperatureService')
      if $_[1] =~ /^(?:method|response)$/;
      shift->SUPER::envelope(@_);
      }

      This is just a simple serializer, one that changes the root element only,
      but a serializer could be used to serialize any part of a message (in this
      case a response).

      You can save your serializer to its own file (in the form of a perl module),
      and then 'use' it. Or alternatively, you can encapsulate the package in a
      BEGIN { } block anywhere in your code. Either way, to tell SOAP::Lite to use
      your serializer as opposed to its own, you will need to do the following
      within your Web service instance:

      SOAP::Transport::HTTP::CGI
      ->serializer(MySerializer->new)
      ->dispatch_to('MyService')
      ->handle;

      The full source code for a service that overrides the root element as
      described above can be found here:
      http://www.majordojo.com/soaplite/examples/customserializer.txt

      I have also posted the answer to your question in my blog:
      http://www.majordojo.com/archives/2003_04.html#000013

      -----Original Message-----
      From: Torsten Mangner [mailto:tmangner@...]
      Sent: Wednesday, April 30, 2003 1:43 AM
      To: Byrne Reese
      Subject: Re: replace namesp1 from method call?


      --- In soaplite@yahoogroups.com, Byrne Reese <breese@g...> wrote:
      > Try this:
      >
      > my $method = SOAP::Data->name("getAllPendingDocumentInfo)
      > ->uri("ns");
      >
      > my $results = $soap->call($method ... )

      ok this works great for sending method calls to the server ... but how
      about the returning values?

      I tried the following, but this has no effect :(

      return SOAP::Data->name('GetCatalogResponse')
      ->prefix('cat')
      ->uri('urn://catalog')
      ->value(...)

      Any suggestions?

      Thanks in advance,
      Torsten
    Your message has been successfully submitted and would be delivered to recipients shortly.