尝试使用PowerShell从Sharepoint获取列表项。
所以我使用了Windows Powershell Blog中的示例,将其修改为与我的网站一起使用。现在我收到以下错误:
使用“7”参数调用“GetListItems”的异常:“抛出类型'Microsoft.SharePoint.SoapServer.SoapServerException'的异常。” 在行:30 char:1 + $ list = $ service.GetListItems($ listName,“”,$ query,$ viewFields,$ rowLimit,$ qu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:SoapException
脚本:
# The uri refers to the path of the service description, e.g. the .asmx page
$uri = "http://SITE/sites/DefaultCollection/Engineering/Subsite%20(UK)/_vti_bin/lists.asmx"
# Create the service
$service = New-WebServiceProxy -Uri $uri -Namespace SpWs -UseDefaultCredential
# The name of the list
$listName = "Test1"
# Create xml query to retrieve list.
$xmlDoc = new-object System.Xml.XmlDocument
$query = $xmlDoc.CreateElement("Query")
$viewFields = $xmlDoc.CreateElement("ViewFields")
$queryOptions = $xmlDoc.CreateElement("QueryOptions")
$query.set_InnerXml("FieldRef Name='Text1'")
$rowLimit = "10"
$list = $null
$service = $null
try
{
$service = New-WebServiceProxy -Uri $uri -Namespace SpWs -UseDefaultCredential
}
catch
{
Write-Error $_ -ErrorAction:'SilentlyContinue'
}
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
if($service -ne $null)
{
try
{
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
}
catch
{
Write-Error $_ -ErrorAction:'SilentlyContinue'
}
}
$list
答案 0 :(得分:3)
这里的解决方案对我有用..
添加"?WSDL"到$ uri字符串的末尾
$uri = "http://SITE/sites/DefaultCollection/Engineering/Subsite%20(UK)/_vti_bin/lists.asmx?WSDL"
根据this link:要返回使用ASP.NET创建的Web服务的服务描述,请附加"?WSDL"到Web服务的URL(例如,http://www.ss64.com/MyWebService.asmx?WSDL)
答案 1 :(得分:0)
它抛出错误的行是:
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
该行没有被捕获,但这里有一个similar issue抛出相同的错误。如果你想尝试获得一个更好的例外,请将该行换成另一个try catch:
try{
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
}
catch{
[System.Exception]
write-host ($_.Exception).Message
}
答案 2 :(得分:-1)
请确保添加"?WSDL"你的URI这就是代码破解的原因。假装它不知道函数的定义(至少我猜)......
如下所示。我很惊讶地看到这使我的代码工作。怪异..
$ uri =" http://<> / sites / DefaultCollection / Engineering / Subsite%20(UK)/_vti_bin/lists.asmx?WSDL"