web-services - 在PowerShell中与[ref]一起使用的参数未填写

标签 web-services sharepoint powershell powershell-2.0

我正在尝试从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/

相关文章:

css - bootstrap 和 jQuery 在 Sharepoint 2013 中无法正常工作

azure - 有没有办法像使用 "AzureAD"模块一样在 "Az"powershell 模块中的身份验证上下文之间进行切换?

java - 安卓 :-Consume a web service through Post method as a json Request and Response

c# - Sharepoint Web 服务项目数据(访问 "Created By"列)

SharePoint 文档工作区权限

模块中的 PowerShell .ps1 文件 cmdlet

powershell - 在 WASP/powershell 中通过窗口获取进程对象?

php - Python SOAP 客户端、授权

java - Java 中的 Post 请求参数不起作用

c# - ASP.NET MVC2 从母版页调用服务方法?