2012-01-22 15 views
3
#use SOAP::Lite (+trace => all, maptype => {}); 
use SOAP::Lite maptype => {}; 
use LWP::UserAgent; 
use HTTP::Request::Common; 

#credentials' file 
require "c:\\test\\pass.pl"; 
my $userAgent = LWP::UserAgent->new(keep_alive => 1); 

sub SOAP::Transport::HTTP::Client::get_basic_credentials { 
    return $username => $password; 
} 
my $soap 
    = SOAP::Lite 
    ->uri('<mysite>/_vti_bin/lists.asmx') 
    ->on_action(sub {join '/', 'http://schemas.microsoft.com/sharepoint/soap/CopyIntoItemsLocal', $_[1]}) 
    ->proxy('<mysite>/_layouts/viewlsts.aspx?BaseType=0', keep_alive => 1); 

# my $method = SOAP::Data->name('CopyIntoItemsLocal') 
# ->attr({xmlns => 'http://schemas.microsoft.com/sharepoint/soap/'}); 
# my @params = (SOAP::Data->name(SourceUrl => $source), 
# SOAP::Data->name(DestinationUrl => $destination)); 
# print $soap->call($method => @params)->result; 

my $fileName = 'c:\test\abc.txt'; 
my $destDir = "<mysite>/Lists/sharepoint1/"; 

#load and encode Data 
my $data; 
open(FILE, $fileName) or die "$!"; 

#read in chunks of 57 bytes to ensure no padding in the middle (Padding means extra space for large files) 
while (read(FILE, $buf, 60 * 57)) { 
    $data .= encode_base64($buf); 
} 
close(FILE); 

#make the call 
print "uploading $fileName..."; 
$lists = $soap->GetList(); 
my $method = SOAP::Data->name('CopyIntoItemsLocal')->attr({xmlns => 'http://schemas.microsoft.com/sharepoint/soap/'}); 
my @params = (
    SOAP::Data->name('SourceUrl')->value($fileName)->type(''), 
    SOAP::Data->name('DestinationUrls')->type('')->value(
     \SOAP::Data->name('string')->type('')->value($destDir . $fileName) 
    ), 
    SOAP::Data->name('Fields')->type('')->value(
     \SOAP::Data->name('FieldInformation')->type('')->attr({Type => 'File'})->value('') 
    ), 
    SOAP::Data->name('Stream')->value("$data")->type('') 

); 

#print Results 
print $soap->call($method => @params)->result; 

#print $response->headerof('//CopyResult')->attr->{ErrorCode}; 
#use SOAP::Lite (+trace => all, maptype => {}); 
use SOAP::Lite maptype => {}; 
use LWP::UserAgent; 
use HTTP::Request::Common; 
use MIME::Base64 qw(encode_base64); 
require "c:\\test\\pass.pl"; 
my $userAgent = LWP::UserAgent->new(keep_alive=>1); 
#setup connection 
sub SOAP::Transport::HTTP::Client::get_basic_credentials { 
return $username => $password; 
} 
my $soap = SOAP::Lite 
     -> uri('http://<mysite>') 
     -> on_action(sub{ join '/', 'http://schemas.microsoft.com/sharepoint/soap', $_[1] }) 
     -> proxy('http://<mysite>/_vti_bin/lists.asmx',keep_alive => 1); 

$lists = $soap->GetListCollection(); 
quit(1, $lists->faultstring()) if defined $lists->fault(); 
my @result = $lists->dataof('//GetListCollectionResult/Lists/List'); 
foreach my $data (@result) { 
    my $attr = $data->attr; 
    foreach my $a qw'Title Description DefaultViewUrl Name ID WebId ItemCount' { 
     printf "%-16s %s\n", $a, $attr->{$a}; 
    } 
    print "\n"; 
} 

認証が動作しているようです。最初に私はGetlistCollectionというWebサービスが動作していると思っていました。そのWebサービスを使用して呼び出したときにページが返されたためです。しかし、私は呼び出しがproxy引数で指定したページを返すと思います。Perl SOAP :: Liteを使用してローカルマシンからSharepointにファイルをアップロードするにはどうすればよいですか?

私は、共有ポイント上の特定のサイトのリストを取得することができます。

私はGetListCollectionを使用しました。しかし、私は本当にリストを印刷しているコードを理解していませんでした。私はsquish.netからコピーしました。今私はCopyIntoItemsLocal Webサービスを使用しようとしています。

私たちは1つのサーバー(SVN)にファイルのリポジトリを持っており、実行するとSVNからディレクトリ構造と共に共有ポイントにファイルとディレクトリをコピーするPerlスクリプトを作成する必要があります。

私はどんなヘルプやヒントもありがとうございます。それは大きな仕事なので、モジュールでやっています。

+0

お手伝いをします。ここであなたの質問を展開してください。いくつかのコードを提供しましたが、何が起こるか、何が起こっているのかを教えてください。 – lhagemann

+0

私はそれを試しましたが運がありませんでした(http://stackoverflow.com/questions/4277340/accessing-a-sharepoint-using-perl-and-webdav)。私はPerlから呼び出されたPowerShellを使用してしまいました(http://stackoverflow.com/questions/4657954/how-to-access-lists-of-a-sub-site-in-sharepoint-using-web-services、http: /www.nivot.org/nivot2/post/2008/02/29/ManipulatingRemoteSharePointListsWithPowerShell.aspx) – eckes

+0

私は前のコードの下にコードを含めました。申し訳ありません。別のセクションに新しいコードを組み込む方法を理解できませんでした。 – Harpreet

答えて

0

オープンソースのsoapUIテストツールsoapUI(以前はeviware、現在はsmartbear)を使用して始めます。これにより、他のユーザーインターフェイスなしで石鹸取引を前後に送ることができます。あなたのトランザクションが正常に動作し、データを解析して必要なものを得ることができたら、Perlを使ってそれらのトランザクションを自動化する動きをします。

これは、リクエストのエラーを早期に解消し、レスポンスを解析する方法を理解し、APIを理解するのに役立ちます。

関連する問題