0
Webサービスを呼び出そうとしています。 Powershellを新しく起動すると、以下のコードが完全に実行されます。それ以降の実行では、次のエラーが発生します。Powershellで引数を2回目に変換できません
Cannot convert argument "fieldsWithValues", with value:
"FileHold.LibraryManager.FieldWithValue[]", for "SetMetadata" to type
"FileHold.LibraryManager.FieldWithValue[]": "Cannot convert the
"FileHold.LibraryManager.FieldWithValue" value of type
"FileHold.LibraryManager.FieldWithValue" to type
"FileHold.LibraryManager.FieldWithValue"."
At Z:\VM_Transfer\Customers\Oregon\UpdateMetadata\CannotConvertTest.ps1:19 char:1
ここに問題のあるコードがあります。
$fh = "http://fileholdtest8/fh/filehold"
$uri = $fh + "/UserRoleManager/SessionManager.asmx?WSDL"
$SessionManager = New-WebServiceProxy -Uri $uri -Namespace FileHold.SessionManager
$sessionId = $SessionManager.StartSession('sysadm', '12345', 4)
$uri = $fh + "/LibraryManager/DocumentManager.asmx?WSDL"
$dm = New-WebServiceProxy -Uri $uri -Namespace FileHold.LibraryManager
$dm.CookieContainer = New-Object System.Net.CookieContainer
$cookie = New-Object System.Net.Cookie('FHLSID', $sessionId, "/", ([System.Uri]$dm.Url).Host)
$dm.CookieContainer.Add($cookie)
$newFieldValue = [FileHold.LibraryManager.FieldWithValue]::new()
$newFieldValue.FieldId = 1007
$newFieldValue.FieldValue = $true
[FileHold.LibraryManager.FieldWithValue[]]$fieldsWithValues = @($newFieldValue)
$dm.SetMetadata(4033, 1002, "EmployeeInfo_filled1-test", $fieldsWithValues, $false, $null)
ISEを再起動せずに毎回これを実行できるようにするには、何が必要ですか。
Btw。このメソッドを使用して、パラメータが単純な型であれば問題なく他のメソッドを呼び出すことができます。問題は、FileHold.LibraryManager.FieldWithValueのような複雑なオブジェクトがある場合にのみ発生するようです。
PSVersion = 5.1.14393.1532
自分自身では「New-WebServiceProxy」は使用しませんが、呼び出すたびにプロキシタイプの新しいセットを生成すると思います。したがって、2回目に呼び出すと、2つの異なる[FileHold.LibraryManager.FieldWithValue]型が実際に取得されます。それらは同じフルネームを持ちますが、それらの間で変換することはできません。 – PetSerAl
私はこれらの行に沿っていくつかのことを試みましたが、失敗し続けました。しかし、あなたは私にそれをもう一度見てもらうように促しました。私は、Webサービス参照変数の存在を間違ってテストしていました。私はそれを[Stej](https://stackoverflow.com/questions/3159949/in-powershell-how-do-i-test-whether-not-a-specific-variable-personershell.html)に従ってTest-Pathで修正しています。グローバルに存在する)、それが機能します。 – Code39