Fedora Linux Support Community & Resources Center
  #1  
Old 20th March 2010, 11:02 AM
meowdin Offline
Registered User
 
Join Date: Feb 2008
Location: HK
Age: 33
Posts: 196
windows_xp_2003firefox
Perl SOAP and returned binary er... thing

Hi community,


I got half a script which intended to download a txt file form a sharepoint server. After struggled with SOAP in perl and the amazingly un-user friendly XML, I finally got the below script worked for authentication and retriving.

Code:
use LWP::UserAgent;
use LWP::Debug;
use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };
use MIME::Base64 qw( decode_base64 );
 use MIME::Base64 qw(encode_base64);

#use SOAP::Lite;
import SOAP::Data 'name', 'value';
SOAP::WSDL::Deserializer::Hash;




$sp_endpoint = 'https://remote.domain.com:345/_vti_bin/Copy.asmx';
$sp_domain = 'remote.domain.com:345';
$sp_username = '192.168.133.124\meowdin';
$sp_password = 'meowdin';


 

 $debug = 1;
 
if ($debug) {
    LWP::Debug::level('+');
    SOAP::Lite->import(+trace => 'all');
}
 
my @ua_args = (keep_alive => 1);
my @credentials = ($sp_domain, "", $sp_username, $sp_password);
my $schema_ua = LWP::UserAgent->new(@ua_args);
$schema_ua->credentials(@credentials);

$soap = SOAP::Lite->proxy($sp_endpoint, @ua_args, credentials => @credentials);
$soap->schema->useragent($schema_ua);
$soap->uri("http://schemas.microsoft.com/sharepoint/soap/");
$soap->transport->credentials( @credentials ); 

$url="https://remote.domain.com:345/Shared%20Documents/test.txt";

$list=$soap->GetItem(SOAP::Data->value(SOAP::Data->name("Url" => $url)));
quit(1, $list->faultstring()) if defined $list->fault();



 my $result=$list->dataof('//GetItemResponse/Stream');

my $file = "time.txt";
$content=decode_base64($result);

#Supposed I am having my file in memory as $content 

#But I find noway for me to put this memory into physical 
Here's the SOAP format specification in that sharepoint server for reference

Code:
Request:

POST /_vti_bin/Copy.asmx HTTP/1.1
Host: remote.bizconline.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/GetItem"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 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>
    <GetItem xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <Url>string</Url>
    </GetItem>
  </soap:Body>
</soap:Envelope>

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length


Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 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>
    <GetItemResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <GetItemResult>unsignedInt</GetItemResult>
      <Fields>
        <FieldInformation Type="Invalid or Integer or Text or Note or DateTime or Counter or Choice or Lookup or Boolean or Number or Currency or URL or Computed or Threading or Guid or MultiChoice or GridChoice or Calculated or File or Attachments or User or Recurrence or CrossProjectLink or ModStat or AllDayEvent or Error" DisplayName="string" InternalName="string" Id="guid" Value="string" />
        <FieldInformation Type="Invalid or Integer or Text or Note or DateTime or Counter or Choice or Lookup or Boolean or Number or Currency or URL or Computed or Threading or Guid or MultiChoice or GridChoice or Calculated or File or Attachments or User or Recurrence or CrossProjectLink or ModStat or AllDayEvent or Error" DisplayName="string" InternalName="string" Id="guid" Value="string" />
      </Fields>
      <Stream>base64Binary</Stream>
    </GetItemResponse>
  </soap:Body>
</soap:Envelope>

It could be possible that I made a wrong assumption and the $content is not containing the file I retrived (the XML return with a chunk of glibberish tho).

Or it could possibly be a simple solution (like the puttofile($content) method in my dream)

In anycase, I will appreciate any input, or even any other approach / method.

I got to run this script on a Linux machine (CentOS or something) tho, so M$ solution could not really help here



Mao Ting

---------- Post added at 06:02 PM CDT ---------- Previous post was at 04:09 PM CDT ----------

Some update:

I have modified my code (the lower part) with these:
Quote:

my @result=$list->dataof('//GetItemResponse/Stream');
my $file = "time.txt";
my $attr="";

open ( FH2 ,">", $file ) || die ("Could not open file. $!");

foreach $data(@result){
$attr= $data->attr;

$content=decode_base64($attr);
print FH2 (utf8::encode($content));

}
It seems the attribute is what I want, and I need to use an array inorder to get them all.

Enven though I get glibberish still, I think I am getting closer ...

Again, any help is much appreciated.
Reply With Quote
  #2  
Old 24th March 2010, 02:01 PM
ibbo Offline
Registered User
 
Join Date: Jun 2005
Location: Leeds
Posts: 1,264
linuxfedorafirefox
Re: Perl SOAP and returned binary er... thing

When using soap::lite I always develop using the following use statement.

use SOAP::Lite +trace => qw(trace debug);

This gives you plenty of output to look at and see whats gone wrong.

Ibbo
__________________
A Hangover Lasts A Day, But Our Drunken Memories Last A Lifetime
--
Linux user #349545
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCfdjyzXscddzQvlhBedAcD7qfKmHo==zx0H
Reply With Quote
  #3  
Old 24th March 2010, 03:57 PM
meowdin Offline
Registered User
 
Join Date: Feb 2008
Location: HK
Age: 33
Posts: 196
windows_xp_2003firefox
Re: Perl SOAP and returned binary er... thing

Hi ibbo,

Thanks for the reply

I must say that I don't really know what I am doing tho,

after changing
use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };

to

use SOAP::Lite +trace => qw(trace debug);

The reply from the server bacame HTTP 1.1 / 500 Internal Server Error =/

There are tones of tags (the whole XML file) on my screen though, the original use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };
actually give me some ok reply with:

<Stream>AEAFSE@TTRR(some rubbish)DGRWGRWG</Stream>

Which I believe those thing* between the stream is my text file.... just don't know how to handle them.

I tried:

Save it in a text => get the exact same thing in the text
Open it as a memory file => open (FH,"<" ,\$result ), don't know what to do next
Encrpt / decrpt then save in text => still getting glibrish
..........

Or other funny stuff except from getting my text file back ....
Reply With Quote
  #4  
Old 12th May 2011, 08:25 AM
bliCaHcl Offline
Registered User
 
Join Date: May 2011
Posts: 1
windows_xp_2003firefox
Re: Perl SOAP and returned binary er... thing

While trying to open for writing, use the one similar to
open(FH, '>:raw', 'Out.xlsx')

This has resolved the issue for me

Here is the code snippet I've used for writing xlsx file

my $result=$list->dataof('//GetItemResponse/Stream');
open(FH, '>:raw', 'Out.xlsx') or die "FH:Out.xlsx:$!\n";
my $content;
foreach my $_tmp (@{$result->{'_value'}}){
$content .=decode_base64($_tmp);
}
print FH $content;
close FH;

Last edited by bliCaHcl; 12th May 2011 at 10:26 AM.
Reply With Quote
  #5  
Old 12th May 2011, 08:56 AM
meowdin Offline
Registered User
 
Join Date: Feb 2008
Location: HK
Age: 33
Posts: 196
windows_xp_2003ie
Re: Perl SOAP and returned binary er... thing

Hi bliCaHcl,

Eventually i skipped this problem by some other means (I forgot how...)

I thank you sincerely for your reply. Maybe next time i give it a try once I got the chance.....
Reply With Quote
Reply

Tags
binary, perl, returned, soap, thing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I have returned! cypher543 Wibble 35 30th March 2007 04:27 AM
Any way to resolve x86_64 Perl issue without yum remove perl.i386? jert Using Fedora 3 24th July 2005 07:31 PM
Can't locate SOAP/Lite.pm in @INC derekivey Using Fedora 2 25th June 2005 12:29 AM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Using Fedora 0 17th December 2004 12:42 AM


Current GMT-time: 14:26 (Sunday, 21-12-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
...Elafonissi - Warung Ayam Bule Instagram Photos - Oslo - Norway Instagram Photos - straight of Gibraltar Travel Photos on Instagram - Hutan Pinus Photos