2011-01-26 75 views
1

我試圖從一個PowerShell腳本調用了SharePoint的Copy.asmx WebService的:out參數沒有填寫

$copyWS = .\Connect-WebService.ps1 $copyWsdlUrl -requiresAuthentication 
$copyWS.UseDefaultCredentials = $true 

[FieldInformation[]]$fieldInfos = $null 
[System.Byte[]]$data = $null 
$copyWS.GetItem($fileUrl, [ref]$fieldInfos, [ref]$data) 

結果:返回的GetItem 0成功,但$ fieldInfos和$ data是$ null。如果我從C#控制檯應用程序執行相同的操作,它會正常工作,data.Length等於我的文件長度。

Copy copyWS = new Copy(); 
copyWS.UseDefaultCredentials = true; 

FieldInformation[] fieldInfos = null; 
byte[] data = null; 
uint result = copyWS.GetItem(fileUrl, out fieldInfos, out data); 

Console.WriteLine(result); 
Console.WriteLine(data.Length); 

我的錯誤在哪裏,或者這是一個PowerShell錯誤?

繼beefarino的意見,我叫$ copyWS.GetItem並獲得:

System.UInt32 GetItem(string Url, 
Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3http___moss__vti_bin_Copy_asmx.FieldInformation[]&, jfww_71i, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Fields, 
System.Byte[]&, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Stream) 

所以我看參數吧,我甚至改變了$ fieldInfos的類型,以顯示全名Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3http___moss__vti_bin_Copy_asmx.FieldInformation[]但無濟於事。

回答

3

假設連接,webservice.ps1最終調用new-webserviceproxy ...

使用get成員驗證從PowerShell中的Web服務方法的簽名:

$copyWS | get-member

或傾倒法給主機而不調用它:

$copyWS.GetItem

代理不總是看起來像你所期望的;例如,對於這種方法:

int GetData(out byte[] value);

通過PowerShell中產生的新webserviceproxy方法是這樣的:

void GetData([ref] $result, [ref] $resultSpecified, [ref] $value)

+0

好一點,爲$ copyWS.GetItem我得到:System.UInt32的GetItem (string Url,Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3http ___ moss__vti_bin_Copy_asmx.FieldInformation []&,jfww_71i,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null Fields,System.Byte []&,mscorlib,Version = 2.0 .0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 Stream) – Hinek 2011-01-26 14:43:50