我正在尝试从PowerShell脚本调用SharePoint的Copy.asmx WebService:
$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错误?
遵循beegarino的建议,我调用了$ 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[]
,但无济于事。
最佳答案
假设connect-webservice.ps1最终调用了new-webserviceproxy ...
使用get-member从powershell验证Web服务方法的签名:$copyWS | get-member
或者通过将方法转储到主机而不调用它:$copyWS.GetItem
代理并不总是像您期望的那样。例如,对于此方法:int GetData(out byte[] value);
powershell生成的new-webserviceproxy方法如下所示:void GetData([ref] $result, [ref] $resultSpecified, [ref] $value)
关于web-services - 在PowerShell中与[ref]一起使用的参数未填写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4804570/