2011-01-26 78 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