PowerShell 中与 [ref] 一起使用的 out 参数未填充
我试图从 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 错误?
按照 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.Auto generatedTypes.WebServiceProxy3http___moss__vti_bin_Copy_asmx.FieldInformation[]< /code> 但无济于事。
I'm trying to call the Copy.asmx WebService of SharePoint from a PowerShell Script:
$copyWS = .\Connect-WebService.ps1 $copyWsdlUrl -requiresAuthentication
$copyWS.UseDefaultCredentials = $true
[FieldInformation[]]$fieldInfos = $null
[System.Byte[]]$data = $null
$copyWS.GetItem($fileUrl, [ref]$fieldInfos, [ref]$data)
Result: GetItem returns 0 for success, but $fieldInfos and $data are $null. If I do the same thing from a C# Console Application, it works fine and data.Length equals my file 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);
Where is my mistake or is this a PowerShell bug?
Following beefarino's advice I called $copyWS.GetItem and got:
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)
So my parameters look right, I even changed the type of $fieldInfos to display the full name Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3http___moss__vti_bin_Copy_asmx.FieldInformation[]
but to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设 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)
Assuming that connect-webservice.ps1 ends up invoking new-webserviceproxy...
Verify the signature of the web service method from powershell using get-member:
$copyWS | get-member
or by dumping the method to the host without invoking it:
$copyWS.GetItem
The proxies don't always look as you'd expect; e.g., for this method:
int GetData(out byte[] value);
the new-webserviceproxy method generated by powershell looks like this:
void GetData([ref] $result, [ref] $resultSpecified, [ref] $value)