Fedora Linux Support Community & Resources Center
Prev Previous Post   Next Post Next
  #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
 

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 16th December 2004 11:42 PM


Current GMT-time: 05:21 (Tuesday, 21-10-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
Antelope Photos - Wakuya Instagram Photos - Brodnica Photos on Instagram