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

Re: Using SOAP to transfer XML document

Expand Messages
  • nonsolosoft
    Hello, the following program now makes the SOAP call and receives the answer. 1) Can I avoid to use LWP::UserAgent to send the $soap_request? 2) If SOAP::Lite
    Message 1 of 8 , Nov 6, 2004
    • 0 Attachment
      Hello,

      the following program now makes the SOAP call and
      receives the answer.

      1) Can I avoid to use LWP::UserAgent to send the $soap_request?
      2) If SOAP::Lite is not able to send a such raw $soap_request,
      can I reinsert the $soap_response into SOAP::Lite to use
      its deserializer and other features?

      #!/usr/bin/perl

      use SOAP::Lite;
      use LWP::UserAgent;

      $var4 = SOAP::Data
      ->name('SBNMarc' => {
      'SbnUser'=> {
      Biblioteca => 'EXXAMM',
      UserId => '010047'
      },
      SbnMessage=> {
      SbnRequest => \SOAP::Data->name('Cerca'=>
      {
      CercaElementoAut => {
      CercaDatiAut => {
      tipoAuthority=>AU,

      canaliCercaDatiAut => {

      T001=>'CFIV006324'
      }
      }
      }
      } )->attr({maxRighe=>"15",
      numPrimo=>"1", tipoOrd=>"1", tipoOutput=\>"000"})
      }
      })->attr({'schemaVersion'=>"1.07",
      'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
      'xsi:noNamespaceSchemaLocation'=>"SBNMarcv107.xsd"});



      $soap_request = SOAP::Lite->serializer->envelope(method=>'freeform',
      $var4);

      $soap_request =~ s/<freeform>// ;
      $soap_request =~ s!</freeform>!! ;


      my $ua = LWP::UserAgent->new();
      my $req = HTTP::Request->new(POST => $SBN::uri);
      $req->authorization_basic($SBN::login, $SBN::password);

      $req->content_type('text/xml');
      $req->content($soap_request);
      my $res = $ua->request($req);
      my $soap_response = $res->as_string;

      print $soap_response->content;






      Best regards, \fer
    • Duncan Cameron
      ... It doesn t have to be this complicated! Your top-level element, SBNMarc, is in effect the remote method to be invoked, and its child elements, Sbnuser
      Message 2 of 8 , Nov 6, 2004
      • 0 Attachment
        On 2004-11-06 at 15:31:50 nonsolosoft wrote:

        >Hello,
        >
        >the following program now makes the SOAP call and
        >receives the answer.
        >
        >1) Can I avoid to use LWP::UserAgent to send the $soap_request?
        >2) If SOAP::Lite is not able to send a such raw $soap_request,
        >can I reinsert the $soap_response into SOAP::Lite to use
        >its deserializer and other features?
        >
        >#!/usr/bin/perl
        >
        >use SOAP::Lite;
        >use LWP::UserAgent;
        >
        >$var4 = SOAP::Data
        > ->name('SBNMarc' => {
        > 'SbnUser'=> {
        > Biblioteca => 'EXXAMM',
        > UserId => '010047'
        > },
        > SbnMessage=> {
        > SbnRequest => \SOAP::Data->name('Cerca'=>
        > {
        > CercaElementoAut => {
        > CercaDatiAut => {
        >
        >tipoAuthority=>AU,
        >
        >canaliCercaDatiAut => {
        >
        >T001=>'CFIV006324'
        > }
        > }
        > }
        > } )->attr({maxRighe=>"15",
        >numPrimo=>"1", tipoOrd=>"1", tipoOutput=\>"000"})
        > }
        > })->attr({'schemaVersion'=>"1.07",
        >'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
        >'xsi:noNamespaceSchemaLocation'=>"SBNMarcv107.xsd"});
        >
        >$soap_request = SOAP::Lite->serializer->envelope(method=>'freeform',
        >$var4);
        >
        >$soap_request =~ s/<freeform>// ;
        >$soap_request =~ s!</freeform>!! ;
        >
        >my $ua = LWP::UserAgent->new();
        >my $req = HTTP::Request->new(POST => $SBN::uri);
        >$req->authorization_basic($SBN::login, $SBN::password);
        >
        >$req->content_type('text/xml');
        >$req->content($soap_request);
        >my $res = $ua->request($req);
        >my $soap_response = $res->as_string;
        >
        >print $soap_response->content;
        >
        It doesn't have to be this complicated!
        Your top-level element, SBNMarc, is in effect the 'remote method' to be
        invoked, and its child elements, Sbnuser and SbnMessage, are the
        parameters.
        So you can use SOAP::Lite directly

        my $user = SOAP::Data->name('SbnUser'=> {
        Biblioteca => 'EXXAMM',
        UserId => '010047'
        });
        my $message = SOAP::Data->name(SbnMessage => {
        SbnRequest => \SOAP::Data->name('Cerca'=> {
        CercaElementoAut => {
        CercaDatiAut => {
        tipoAuthority=>AU,canaliCercaDatiAut => {T001=>'CFIV006324'}
        }
        } )->attr({maxRighe=>"15",numPrimo=>"1", tipoOrd=> "1",
        tipoOutput=> "000"})
        });

        my $method = SOAP::Data
        ->name('SBNMarc')
        ->attr({
        'schemaVersion'=>"1.07",
        'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
        'xsi:noNamespaceSchemaLocation'=>"SBNMarcv107.xsd"
        })
        ->uri('')
        ;
        my $s = SOAP::Lite
        ->proxy(...)
        ->uri(...)
        ;
        $s->call($method, $user, $message);

        The 'freeform' approach is undocumented and I don't see a way of using
        it at present. But you misunderstood how to use it, 'freeform' is
        actually the name of the serialiser method to be invoked:

        SOAP::Lite->serializer->freeform($var4);

        Regarding your question about deserialising, you can create a
        SOAP::Deserializer and give it any xml to be deserialised. See the docs
        for an example.

        Regards
        Duncan
      • nonsolosoft
        ... From WDSL SBNMarc was defined as element and not as method. Anyway, thank you: your solution works fine and I ll go on in this direction. Bye,
        Message 3 of 8 , Nov 6, 2004
        • 0 Attachment
          --- In soaplite@yahoogroups.com, "Duncan Cameron"
          <duncan_cameron2002@y...> wrote:

          > It doesn't have to be this complicated!
          > Your top-level element, SBNMarc, is in effect the 'remote method' to be
          > invoked, and its child elements, Sbnuser and SbnMessage, are the
          > parameters.
          > So you can use SOAP::Lite directly

          From WDSL SBNMarc was defined as element and not as method.
          Anyway, thank you: your solution works fine and I'll go on
          in this direction.

          Bye, \fer
        • Byrne Reese
          Judging by the original message in this thread you are looking for a way to post an XML document to a URL, but you don t want all the SOAP Envelope, SOAP Body
          Message 4 of 8 , Nov 14, 2004
          • 0 Attachment
            Judging by the original message in this thread you are looking for a way
            to post an XML document to a URL, but you don't want all the SOAP
            Envelope, SOAP Body stuff. Is that correct?

            If so, let me suggest you try using the following modules togethers:

            1) XML::Simple
            2) LWP

            XML::Simple allows you to contruct and parse XML documents using simple
            perl HASHs.

            LWP provides a way for you to send payloads over HTTP.

            If you need more help - let me know. Or if you DO want all the SOAP
            stuff, I can certainly help.

            Byrne

            nonsolosoft wrote:

            >
            > --- In soaplite@yahoogroups.com, "nonsolosoft" <nonsolosoft@d...> wrote:
            > >
            > > Only with SOAP::Lite I've been able to construnct a such complex SOAP
            > > Message without trouble (I've tried also XML::Generator, XML::Simple,
            > > etc.).
            > > It's a such pity not be able from SOAP::Lite to transfer that message,
            > > using SOAP::Lite as transfer instead of RPC.
            > >
            >
            > I was looking in the SOAP::Lite source code:
            > in the envelope()
            > there is:
            >
            > } elsif ($type eq 'freeform') {
            > SOAP::Trace::freeform(@parameters);
            > $body = SOAP::Data->set_value(@parameters);
            > } ...
            >
            > Where have I to specify 'freeform' to use this code?
            > Shall it do what I need?
            >
            >
            > Best regards, \fer
          • nonsolosoft
            ... way ... No, I need the SOAP Envelope, Body and so on. But the SOAP Server has not defined a valid method. Thank Duncan Cameron to have suggested me to use
            Message 5 of 8 , Nov 15, 2004
            • 0 Attachment
              --- In soaplite@yahoogroups.com, Byrne Reese <byrne@m...> wrote:
              > Judging by the original message in this thread you are looking for a
              way
              > to post an XML document to a URL, but you don't want all the SOAP
              > Envelope, SOAP Body stuff. Is that correct?

              No, I need the SOAP Envelope, Body and so on.
              But the SOAP Server has not defined a valid method.
              Thank Duncan Cameron to have suggested me to use the outer XML element
              as method; it works now.

              Thank you Byrne Reese too.

              Bye, \fer
            Your message has been successfully submitted and would be delivered to recipients shortly.