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

Server doesn't send the attachment ?

Expand Messages
  • CristiAn Fuenzalida
    Hello !! :-) I want to send a request from the client to the server with an attachment. Then i need to send another attachment from the server to the client,
    Message 1 of 1 , Sep 2, 2005
    View Source
    • 0 Attachment
      Hello !! :-)

      I want to send a request from the client to the server with an attachment.  Then i need to send another attachment from the server to the client, and parse it at the client.

      The problem is that i can't send the attachment from the server :-(.  I've succesfully sent an attachment from the client to the server, but no from server to client. Does anybody knows if its possibly to recieve an attachment at the client ?, Is it something wrong with my code  ?.

      As you can also note in the execution trace, only the client send an attachment, while the server, just return a number, and don't send the attachment using this code:

      return SOAP::Data->name('convertedTemp' => (((9/5)*($temp->value)) + 32)), $ent;

      where $ent is a MIME::Entity object. Is this the correct form to sending an attachment from the server to a client ?.


      Thanks a lot !!



      CLIENT CODE

      #!/usr/bin/perl
        use SOAP::Lite +"trace";
        use MIME::Entity;
        use Data::Dumper;
       
        my $ent = build MIME::Entity
          Type        => "text/plain",
          Path        => "texto_cliente.txt",
          Filename    => "texto_cliente.txt",
          Disposition => "attachment";
        $NS = "TemperatureService";
        $PROXY = 'http://127.0.0.1/ws/test/servidor.cgi';
        my $client = SOAP::Lite
          ->packager(SOAP::Packager::MIME->new)
          ->parts([ $ent ])
          ->uri($NS)
          ->proxy($PROXY);
        $response = $client->c2f(SOAP::Data->name("temperature" => '100'));
        print $response->valueof('//c2fResponse/foo');

        if( $response->is_multipart() ) {
          print  "***Response is Multipart *** \n";
        }
        foreach my $part (@{$response->parts}) {
          print  "soaplite.cgi: attachment found! (".ref($part).")\n";
          print  "soaplite.cgi: contents => ".$part->stringify."\n";
        }


      SERVER CODE

      #!/usr/bin/perl
      use SOAP::Transport::HTTP;
      use MIME::Entity;
        my $packager = SOAP::Packager::MIME->new;
        SOAP::Transport::HTTP::CGI
          ->packager(SOAP::Packager::MIME->new)
          ->dispatch_to('TemperatureService')
          ->handle;

        BEGIN {
          package TemperatureService;
          use vars qw(@ISA);
          @ISA = qw(Exporter SOAP::Server::Parameters);
          use SOAP::Lite;
          sub c2f {
            my $self = shift;
            my $envelope = pop;
            my $temp = $envelope->dataof("//c2f/temperature");
            use MIME::Entity;
            my $ent = build MIME::Entity
              Type        => "text/plain",
              Path        => "texto_server.txt",
              Filename    => "texto_server.txt",
              Disposition => "attachment";
            # read attachments
            foreach my $part (@{$envelope->parts}) {
              print STDERR "soaplite.cgi: attachment found! (".ref($part).")\n";
              print STDERR "soaplite.cgi: contents => ".$part->stringify."\n";
            }
            # send attachments
            return SOAP::Data->name('convertedTemp' => (((9/5)*($temp->value)) + 32)), $ent;
          }
        }



      EXECUTION TRACE

      devel@devel:~/www/ws/test/> perl cliente.pl
      SOAP::Transport::new: ()
      SOAP::Serializer::new: ()
      SOAP::Deserializer::new: ()
      SOAP::Parser::new: ()
      SOAP::Lite::new: ()
      SOAP::Transport::HTTP::Client::new: ()
      SOAP::Data::new: ()
      SOAP::Lite::call: ()
      SOAP::Serializer::envelope: ()
      SOAP::Serializer::envelope: c2f SOAP::Data=HASH(0x8510c80)
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x85149d0)
      SOAP::Transport::HTTP::Client::send_receive: POST http://127.0.0.1/ws/test/servidor.cgi HTTP/1.1
      Accept: text/xml
      Accept: multipart/*
      Accept: application/soap
      Content-Length: 971
      Content-Type: Multipart/Related; type="text/xml"; start="<main_envelope>"; boundary="----------=_1125681924-30893-0"; charset=utf-8
      SOAPAction: "TemperatureService#c2f"

      This is a multi-part message in MIME format...

      ------------=_1125681924-30893-0
      Content-Type: text/xml
      Content-Disposition: inline
      Content-Location: /main_envelope
      Content-Id: <main_envelope>

      <?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><namesp1:c2f xmlns:namesp1="TemperatureService"><temperature xsi:type="xsd:int">100</temperature></namesp1:c2f></soap:Body></soap:Envelope>
      ------------=_1125681924-30893-0
      Content-Type: text/plain; name="texto_cliente.txt"
      Content-Disposition: attachment; filename="texto_cliente.txt"
      Content-Transfer-Encoding: binary
      MIME-Version: 1.0
      X-Mailer: MIME-tools 5.417 (Entity 5.417)

      Texto cliente
      1983



      ------------=_1125681924-30893-0--

      SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x86f7b04)
      SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
      Connection: close
      Date: Fri, 02 Sep 2005 17:25:24 GMT
      Server: Apache
      Content-Length: 498
      Content-Type: text/xml; charset=utf-8
      Client-Date: Fri, 02 Sep 2005 17:25:24 GMT
      Client-Response-Num: 1
      Set-Cookie: _tracking=192.168.0.40.300491125681924311; path=/; expires=Thu, 01-Dec-05 17:25:24 GMT; domain=.127.0.0.1
      SOAPServer: SOAP::Lite/Perl/0.65_3

      <?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><namesp2:c2fResponse xmlns:namesp2="TemperatureService"><convertedTemp xsi:type="xsd:int">212</convertedTemp></namesp2:c2fResponse></soap:Body></soap:Envelope>
      SOAP::Deserializer::deserialize: ()
      SOAP::Parser::decode: ()
      SOAP::SOM::new: ()
      ***Response is Multipart ***
      SOAP::Lite::DESTROY: ()
      SOAP::Serializer::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Transport::DESTROY: ()
      SOAP::Transport::HTTP::Client::DESTROY: ()
      SOAP::Deserializer::DESTROY: ()
      SOAP::Parser::DESTROY: ()
      SOAP::SOM::DESTROY: ()



      Regards,
      --

          CristiAn.
    Your message has been successfully submitted and would be delivered to recipients shortly.