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

SOAP::Lite using documnet/literal example

Expand Messages
  • arun9a
    I had to spent many hours to find how to access document/literal web services using SOAP:Lite. Cant believe SOAP::Lite folks didnt have time to write a simple
    Message 1 of 2 , Jul 2, 2005
    • 0 Attachment
      I had to spent many hours to find how to access document/literal
      web services using SOAP:Lite. Cant believe SOAP::Lite folks didnt
      have time to write a simple example. Too bad... anyway.. i kind a
      figured it out and it is working well.


      Before you start you would need the following perl modules

      SOAP::Lite (SOAP-Lite-0.60)
      XML::Parser(XML-Parser-2.34)

      NOTE: Install the SOAP::Lite using CPAN will automaticall install
      the XML::Parser. If it doesnt do that then install the XML::Parser
      module.


      SOAP call input (To the web service) from the perl client.
      This is the output of the per client to the web services.
      =========================================================
      ----- start----
      <SOAP-ENV:Envelope
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <SOAP-ENV:Body>

      <lookupTicketRequest xmlns="urn:zzz:xml:ns:pmp-1.0">

      <ticketNumber>1234</ticketNumber>

      </lookupTicketRequest>

      </SOAP-ENV:Body>

      </SOAP-ENV:Envelope>
      ---- end----

      Here the URL is "urn:zzz:xml:ns:pmp-1.0"

      NOTE: MAKE SURE THE URN IS CORRECT BEFORE YOU CALL. IF THE URN IS
      NOT CORRECT YOUR THE STRUCTURE OF THE SOAP DOCUMENT WILL BECOME
      INCORRECT.




      SOAP call output (From the web service)
      This is the output of the web service after processing the request.
      ===================================================
      ----- start ----
      <SOAP-ENV:Envelope
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <SOAP-ENV:Body>

      <ns:lookupTicketResponse xmlns:ns="urn:zzz:xml:ns:pmp-1.0">

      <ns:result code="100">

      <ns:message>Successfull</ns:message>

      </ns:result>

      </ns:lookupTicketResponse>

      </SOAP-ENV:Body>

      </SOAP-ENV:Envelope>
      ----- end ----


      ===========================================
      PERL CODE THAT DOES THE TRICK
      ===========================================

      This Perl code uses SOAP::Lite to access a document/literal web service.
      The web service is hosted in BEA.


      ---- program start ----------
      use strict;
      use SOAP::Lite;

      # IMPORTANT
      #
      # uri "urn:zzz:xml:ns:pmp-1.0" is the key to this document/litral
      type. Make
      # sure you have the correct uri.


      my $soap = SOAP::Lite
      -> uri('urn:zzz:xml:ns:pmp-1.0')
      -> on_action( sub { return
      '"http://localhost:7001/WebServices/pmp10.jws/lookupTicketRequest"' } )
      -> proxy('http://localhost:7001/WebServices/pmp10.jws');

      #Set the operation to call
      my $method = SOAP::Data->name('lookupTicketRequest')
      ->attr({xmlns => 'urn:zzz:xml:ns:pmp-1.0'});

      #Set data elements
      my $query = SOAP::Data->name(ticketNumber => '123456');

      my $result = SOAP::SOM->new;

      #Call the service
      $result = $soap->call($method => $query);

      unless ($result->fault) {

      #Get 'result' element of element 'lookupTicketResponse'
      my $result1 = $result->valueof('//lookupTicketResponse/result');

      #Get the 'code' attribute of element 'result'
      print "Code =
      ".$result->dataof('//lookupTicketResponse/result')->attr->{'code'}."\n";

      #Get the element 'message' of element 'result'
      print "Message =
      ".$result->valueof('//lookupTicketResponse/result/message');

      print "\n";

      } else {
      print join ', ',
      $result->faultcode,
      $result->faultstring,
      $result->faultdetail;
      }
      ---- end program ------------

      ========================
      OUTPUT OF THIS PROGRAM
      ========================

      Code =100
      Message =Successfull
    • arun9a
      I had to spent many hours to find how to access document/literal web services using SOAP:Lite. Cant believe SOAP::Lite folks didnt have time to write a simple
      Message 2 of 2 , Jul 2, 2005
      • 0 Attachment
        I had to spent many hours to find how to access document/literal
        web services using SOAP:Lite. Cant believe SOAP::Lite folks didnt
        have time to write a simple example. Too bad... anyway.. i kind a
        figured it out and it is working well.


        Before you start you would need the following perl modules

        SOAP::Lite (SOAP-Lite-0.60)
        XML::Parser(XML-Parser-2.34)

        NOTE: Install the SOAP::Lite using CPAN will automaticall install
        the XML::Parser. If it doesnt do that then install the XML::Parser
        module.


        SOAP call input (To the web service) from the perl client.
        This is the output of the per client to the web services.
        =========================================================
        ----- start----
        <SOAP-ENV:Envelope
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

        <SOAP-ENV:Body>

        <lookupTicketRequest xmlns="urn:zzz:xml:ns:pmp-1.0">

        <ticketNumber>1234</ticketNumber>

        </lookupTicketRequest>

        </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
        ---- end----

        Here the URL is "urn:zzz:xml:ns:pmp-1.0"

        NOTE: MAKE SURE THE URN IS CORRECT BEFORE YOU CALL. IF THE URN IS
        NOT CORRECT YOUR THE STRUCTURE OF THE SOAP DOCUMENT WILL BECOME
        INCORRECT.




        SOAP call output (From the web service)
        This is the output of the web service after processing the request.
        ===================================================
        ----- start ----
        <SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

        <SOAP-ENV:Body>

        <ns:lookupTicketResponse xmlns:ns="urn:zzz:xml:ns:pmp-1.0">

        <ns:result code="100">

        <ns:message>Successfull</ns:message>

        </ns:result>

        </ns:lookupTicketResponse>

        </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
        ----- end ----


        ===========================================
        PERL CODE THAT DOES THE TRICK
        ===========================================

        This Perl code uses SOAP::Lite to access a document/literal web service.
        The web service is hosted in BEA.


        ---- program start ----------
        use strict;
        use SOAP::Lite;

        # IMPORTANT
        #
        # uri "urn:zzz:xml:ns:pmp-1.0" is the key to this document/litral
        type. Make
        # sure you have the correct uri.


        my $soap = SOAP::Lite
        -> uri('urn:zzz:xml:ns:pmp-1.0')
        -> on_action( sub { return
        '"http://localhost:7001/WebServices/pmp10.jws/lookupTicketRequest"' } )
        -> proxy('http://localhost:7001/WebServices/pmp10.jws');

        #Set the operation to call
        my $method = SOAP::Data->name('lookupTicketRequest')
        ->attr({xmlns => 'urn:zzz:xml:ns:pmp-1.0'});

        #Set data elements
        my $query = SOAP::Data->name(ticketNumber => '123456');

        my $result = SOAP::SOM->new;

        #Call the service
        $result = $soap->call($method => $query);

        unless ($result->fault) {

        #Get 'result' element of element 'lookupTicketResponse'
        my $result1 = $result->valueof('//lookupTicketResponse/result');

        #Get the 'code' attribute of element 'result'
        print "Code =
        ".$result->dataof('//lookupTicketResponse/result')->attr->{'code'}."\n";

        #Get the element 'message' of element 'result'
        print "Message =
        ".$result->valueof('//lookupTicketResponse/result/message');

        print "\n";

        } else {
        print join ', ',
        $result->faultcode,
        $result->faultstring,
        $result->faultdetail;
        }
        ---- end program ------------

        ========================
        OUTPUT OF THIS PROGRAM
        ========================

        Code =100
        Message =Successfull
      Your message has been successfully submitted and would be delivered to recipients shortly.