Вопрос

(Updated 5/19/14)

I'm trying to write a Perl script using SOAP::Lite to add a new item to a Sharepoint list with the UpdateListItems method.

I don't have much experience with SOAP, so I've been using these sources to write my code:
http://www.squish.net/log/2008/10/11/perl-sharepoint/
http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx

I tried copying directly from the the squish.net page, but when that didn't work out, I rewrote some of it using the SOAP::Data documentation. Here's what I've got so far, just trying to create a list item with a title and a comment because those are the required fields. (I checked, those are the correct internal names for the fields)

use LWP::UserAgent;
use LWP::Debug;
use LWP::Authen::Ntlm;
use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string }, 'debug' ];
import SOAP::Data;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;

our $sp_endpoint = 'https://sharepoint.<DOMAIN>.com/';
our $sp_domain = 'sharepoint.<DOMAIN>.com:443';
our $sp_username = '<USERNAME>';
our $sp_password = '<PASSWORD>';

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/UpdateListItems");

my $title = SOAP::Data->name('Field')->value('test title')->attr({'Name' => 'Title'});
my $comment = SOAP::Data->name('Field')->value('test comment')->attr({'Name' => 'Comment'});
my @fields = ($title, $comment);
my $method = SOAP::Data->name('Method')->value(\@fields)->attr({'ID' => '1', 'Cmd' => 'New'});
my $batch = SOAP::Data->name('Batch')->value(\$method)->attr({'OnError' => 'Continue', 'ListVersion' => '1'});
my $in_updates = SOAP::Data->name('updates')->value(\$batch);
my $lists = $soap->UpdateListItems($in_listName, $in_updates);
quit(1, $lists->faultstring()) if defined $lists->fault();

I set PERL_LWP_SSL_VERIFY_HOSTNAME to 0 because I couldn't get the certificate authentication to work, and that seemed to be a good solution at least for now.

Running it gives me this response:

POST https://sharepoint.<DOMAIN>.com/ HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 838
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems#UpdateListItems"

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body>
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems">
<listName xsi:type="xsd:string">{2CC9AAAA-4884-4331-B7C9-E724A92BBFC2}</listName>
<updates>
    <Batch ListVersion="1" OnError="Continue">
    <Method Cmd="New" ID="1" soapenc:arrayType="xsd:string[2]" xsi:type="soapenc:Array">
    <Field Name="Title" xsi:type="xsd:string">test title</Field>
    <Field Name="Comment" xsi:type="xsd:string">test comment</Field>
    </Method></Batch>
</updates>
</UpdateListItems>
</soap:Body></soap:Envelope>
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Mon, 19 May 2014 20:48:59 GMT
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
Content-Length: 48464
Content-Type: text/html; charset=utf-8
Expires: Sun, 04 May 2014 20:48:59 GMT
Last-Modified: Mon, 19 May 2014 20:48:59 GMT
Client-Date: Mon, 19 May 2014 20:49:00 GMT
Client-Peer: 10.9.154.101:443
Client-Response-Num: 6
Client-SSL-Cert-Issuer: /C=US/O=*** Corporation/CN=*** Intranet Basic Issuing CA 2A
Client-SSL-Cert-Subject: /CN=sharepoint.<DOMAIN>.com
Client-SSL-Cipher: RC4-SHA
Client-SSL-Socket-Class: IO::Socket::SSL
Client-SSL-Warning: Peer certificate not verified
Link: </Style%20Library/en-US/Themable/Core%20Styles/controls.css>; rel="stylesheet"; type="text/css"
Link: </_layouts/1033/styles/layouts.css>; rel="stylesheet"; type="text/css"
Link: </Style%20Library/en-US/Core%20Styles/page-layouts-21.css>; rel="stylesheet"; type="text/css"
Link: </_layouts/1033/styles/Themable/search.css?rev=T%2Bhraxktc1A8EnaG5gGMHQ%3D%3D>; rel="stylesheet"; type="text/css"
Link: </_layouts/1033/styles/Themable/corev4.css?rev=p63%2BuzTeSJc22nVGNZ5zwg%3D%3D>; rel="stylesheet"; type="text/css"
Link: </_vti_bin/spsdisco.aspx>; rel="alternate"; type="text/xml"
Link: </_layouts/images/favicon.ico>; rel="shortcut icon"; type="image/vnd.microsoft.icon"
MicrosoftSharePointTeamServices: 14.0.0.7108
Persistent-Auth: true
SPRequestGuid: c40f028a-bb5b-4f38-87d9-5ca7ff80d899
Title: home
X-AspNet-Version: 2.0.50727
X-Meta-GENERATOR: Microsoft SharePoint
X-Meta-Progid: SharePoint.WebPartPage.Document
X-MS-InvokeApp: 1; RequireReadOnly
X-Powered-By: ASP.NET
X-SharePointHealthScore: 2
X-UA-Compatible: IE=8

And then it prints out the html source of the page specified in the $sp_endpoint variable.

There don't seem to be any errors, but it doesn't add anything to the list. I tried a few different values for $sp_endpoint because I'm not sure if it's supposed to be the page for the list itself or just the root, but everything I've tried has been unable to actually update the list.
Any tips as to what would help fix or diagnose the problem would be greatly appreciated. Thanks!

Это было полезно?

Решение

Fixed it. Here's some code that actually works:

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;

use LWP::UserAgent;
use LWP::Debug;
use LWP::Authen::Ntlm;
use Authen::NTLM;
use SOAP::Lite;
import SOAP::Data;
use Data::Dumper;
ntlmv2(1);

our $sp_endpoint = 'https://sharepoint.<DOMAIN>.com/sites/<PATH>/_vti_bin/Lists.asmx';
our $sp_domain = 'sharepoint.<DOMAIN>.com:443';
our $sp_username = '\\<USERNAME>';
our $sp_password = '<PASSWORD>';

our @ua_args = (keep_alive => 1);
our @credentials = ($sp_domain, '', $sp_username, $sp_password);
our $schema_ua = LWP::UserAgent->new(@ua_args);
$schema_ua->credentials(@credentials);
our $soap = SOAP::Lite->proxy($sp_endpoint, @ua_args, credentials => \@credentials)->default_ns('http://schemas.microsoft.com/sharepoint/soap/')->on_action(sub { $_[0].$_[1] });
$soap->schema->useragent($schema_ua);

our $in_listName = SOAP::Data->name('listName')->value('{2CC9AAAA-4884-4331-B7C9-E724A92BBFC2}');

our $titleField = SOAP::Data->name('Field')->value('test title')->attr({'Name' => 'Title'});
our $commentField = SOAP::Data->name('Field')->value('test comment')->attr({'Name' => 'Comment'});
our @fields = ($titleField, $commentField);
our $method = SOAP::Data->name('Method')->value(\@fields)->attr({'ID' => '1', 'Cmd' => 'New'});
our $batch = SOAP::Data->name('Batch')->value(\$method)->attr({'OnError' => 'Return', 'ListVersion' => '1'});
our $in_updates = SOAP::Data->name('updates')->value(\$batch);

$soap->UpdateListItems($in_listName, $in_updates);

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=1;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top