【问题标题】:Download file from Sharepoint library via web services using nusoap使用 nusoap 通过 Web 服务从 Sharepoint 库下载文件
【发布时间】:2015-01-30 17:52:51
【问题描述】:

我正在尝试使用 nusoap 客户端通过 Web 服务从 Sharepoint 库下载文件。我可以使用 Lists.wsdl 连接并获取 List 内容,但我无法确定 Copy.wsdl 方法的参数。

<?php

require_once('lib/nusoap.php');

$username = 'domain\user';
$password = 'secret';
$rowLimit = '0';

$listGuid = "{0379989D-8639-430B-9FD0-96551B7EAB29}";

//Lists.wsdl copied from the Sharepoint site and stored on local drive
$wsdl = "http://localhost/sp/Lists.wsdl";
//NTLM authentication.
$client = new nusoap_client($wsdl, true);
$client->setCredentials('','','ntlm');
$client->useHTTPPersistentConnection();
$client->setCurlOption(CURLOPT_USERPWD, $username.':'.$password);

//XML for the request
$getItemsXml ='
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>'.$listGuid.'</listName>
<rowLimit>'.$rowLimit.'</rowLimit>
</GetListItems>
';

//This works and returns requested data from a list
$result = $client->call('GetListItems', $getItemsXml);
$responseContent = substr($client->response,strpos($client->response, "<"),strlen($client->response)-1);


//This part does not work
//Library ID
$fileGuid = "{A24306B5-50E9-44C0-9728-69E2D015B689}";

$cwsdl = "http://localhost/sp/Copy.wsdl";
$cclient = new nusoap_client($cwsdl, true);
$cclient->setCredentials('','','ntlm');
$cclient->useHTTPPersistentConnection();
$cclient->setCurlOption(CURLOPT_USERPWD, $username.':'.$password);

//This is where I get lost
$fileParams = array();
$cResult = array(0);
$fieldInformationCollection = array('fieldInformation'=>array('DisplayName'=>'', 'Id'=>'', 'InternalName'=>'', 'Type'=>'', 'Value'=>''));
$content = array('');

$fileParams[] = "http://site.example.com/subsite/folder/somefile.pdf";
$fileParams[] = $cResult;
$fileParams[] = $fieldInformation;
$fileParams[] = $content;

//This call fails
$result = $cclient->call('GetItem', $fileParams);

?>

来自失败调用的调试信息显示某些参数是错误的,但我无法弄清楚。

wsdl: in serializeType: uqType: GetItem, ns: http://schemas.microsoft.com/sharepoint/soap/, phptype: struct, arrayType: 
wsdl: in serializeType: phpType is struct, but value is not an array
wsdl: in serializeType: returning: 
wsdl: serializeRPCParameters returning: 
nusoap_client: got wsdl error: phpType is struct, but value is not an array: see debug output for details

我已尝试阅读(并理解)Copy.wsdl 文件并完成调试输出,但没有骰子。

有人搞定这个吗?谢谢。

【问题讨论】:

    标签: php web-services sharepoint wsdl nusoap


    【解决方案1】:

    所以经过几个小时的调试后,我发现答案非常简单。唯一需要发送的参数是要下载的文件的 URL,如下所示:

    //Set URL of the file
    $file['Url'] = 'http://site.example.com/subsite/Folder/requested_file.ext';
    
    //Call nusoap client
    $result = $cclient->call('GetItem', $file);
    

    该参数需要是一个关联数组,其中包含一个名为“Url”的元素。

    客户端将返回一个数组,其中包含元素“GetItemResult”(成功时设置为 0)、“Fields”(包含库中文件的各种信息的 75 个数组的数组),最后是包含 Base64 编码的“Stream”字符串中的文件内容。

    file_put_contents('c:/temp/requested_file.ext', base64_decode($result['Stream']));
    

    【讨论】:

      猜你喜欢
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多