Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell, web services and object types

I'm new to using web services under powershell, so maybe I have a basic misunderstanding about something. I'm working with Microsoft's Reporting Services. Here is a repro script.

$computer = "rptdev"
$uri = "http://$($computer)/ReportServer/ReportService.asmx?WSDL"

$reporting = New-WebServiceProxy -uri $uri -UseDefaultCredential -namespace "ReportingWebService"

$dsRef = new-object ReportingWebService.DataSourceReference
$ds = new-object ReportingWebService.DataSource

$dsRef.GetType()
$ds.GetType()

If I run that, I get something that looks more or less like this:

Name                BaseType
----                --------
DataSourceReference ReportingWebService.DataSourceDefinitionOrReference
DataSource          System.Object

So, my question is: Why does DataSource have System.Object as a BaseType when DataSourceReference clearly has a object type that is based on the web object? They were both created from the ReportingWebService namespace, weren't they?

My root problem is that I need to hand an array of DataSources back to SetItemDataSources, and SetItemDataSources chokes on an array of System.Objects, and I don't seem to be able to cast it to what I want.

like image 867
Darin Strait Avatar asked Nov 06 '22 20:11

Darin Strait


1 Answers

All this means is that the "DataSource" class inherits directly from System.Object. Whereas "DataSourceReference" inherits from "DataSourceDefinitionOrReference", then maybe something else, then System.Object.

However, I do not think that is your problem. Your problem is probably PowerShell's automatic splitting and recombining of collections as generic collections of System.Object. You can control this by setting a static type on the collection like so (I'm guessing on this API you are using since I haven't used it myself):

$computer = "rptdev"
$uri = "http://$($computer)/ReportServer/ReportService.asmx?WSDL"

$reporting = New-WebServiceProxy -uri $uri -UseDefaultCredential -namespace "ReportingWebService"

[ReportingWebService.DataSource[]]$DataSources = <do something to get your data sources>
$reporting.SetItemDataSources($DataSources)
like image 51
JasonMArcher Avatar answered Nov 12 '22 17:11

JasonMArcher