[英]Powershell: Exception calling “AttachDatabase” with “3” argument(s)
[英]PowerShell: Exception calling “GetListItems” with “7” argument(s)
尝试使用 PowerShell 从 SharePoint 获取列表项。
我使用了Windows PowerShell 博客中的示例,对其进行了修改以用于我的站点。 现在我收到以下错误:
Exception calling "GetListItems" with "7" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
At line: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'
}
}
有人试过这个吗? 我该如何解决这个问题?
这是对我有用的解决方案..
将“?WSDL”添加到 $uri 字符串的末尾
$uri = "http://SITE/sites/DefaultCollection/Engineering/Subsite%20(UK)/_vti_bin/lists.asmx?WSDL"
根据此链接:要返回使用 ASP.NET 创建的 Web 服务的服务描述,请将“?WSDL”附加到 Web 服务的 URL(例如, http://www.ss64.com/MyWebService .asmx?WSDL )
它抛出错误的行是:
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
该行没有被捕获,但这里有一个类似的问题,抛出相同的错误。 如果您想尝试获得更好的异常,请将该行包装在另一个 try catch 中:
try{
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
}
catch{
[System.Exception]
write-host ($_.Exception).Message
}
请确保在您的 URI 中添加“?WSDL”,这就是代码中断的原因。 假装它不知道函数的定义(至少我猜)......
像下面那个。 我很惊讶地看到这使我的代码工作。 奇怪的..
$uri = "http://<>/sites/DefaultCollection/Engineering/Subsite%20(UK)/_vti_bin/lists.asmx?WSDL"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.