I'm working with some SOAP-based Web services (Opsware Twister, to be more specific) via New-WebServiceProxy cmdlet (obviously) and encountered some difficulties when providing parameters for methods I call - it results in typecasting error. Here's the code:
$user = "myuser"
$passw = Get-Content "z:\creds.txt" | ConvertTo-SecureString
$hpsa_core = "core.dom.loc"
$creds = [PSCredential]::New($user, $passw)
$URI_ss = "https://$hpsa_core/osapi/com/opsware/server/ServerService?WSDL"
$ws_ss = New-WebServiceProxy -URI $URI_ss -Credential $creds -Namespace 'ns_ss'
$URI_search = "https://$hpsa_core/osapi/com/opsware/search/SearchService?WSDL"
$ws_search = New-WebServiceProxy -URI $URI_search -Credential $creds -Namespace 'ns_search'
$hostname = "SQLSERVER1.dom.loc"
$objectType = "device"
$expression = "ServerVO.hostname CONTAINS $hostname"
$filter = [ns_search.Filter] @{
objectType = $objectType
expression = $expression
}
$refs = $ws_ss.findServerRefs($filter)
The problem is, that findServerRefs method expects not a primitive type, but another class (com.opsware.search.Filter), and methods to create its instance are not exposed via the service. This straightforward approach doesn't work, resulting in error:
Cannot convert argument "filter", with value: "ns_search.Filter", for "findServerRefs" to type "ns_ss.Filter": "Cannot convert the "ns_search.Filter" value of type "ns_search.Filter" to type "ns_ss.Filter"." At line:36 char:1 + $refs = $ws_ss.findServerRefs($filter) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
SearchService is implemented as Java interface (com.opsware.search -Interface SearchService)
Am I using the wrong approach?
One important remark: there is an integration component for Powershell from the vendor (DLL) which provides an easeir experience, but I want to achieve the same results with pure Powershell functionality (if it is possible at all).