簡體   English   中英

PowerShell:使用“7”參數調用“GetListItems”異常

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM