开发者

out Parameter used with [ref] in PowerShell are not filled

开发者 https://www.devze.com 2023-02-06 16:01 出处:网络
I\'m trying to call the Copy.asmx WebService of SharePoint from a PowerShell Script: $copyWS = .\\Connect-WebService.ps1 $copyWsdlUrl -requiresAuthentication

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 开发者_如何学PythonI 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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消