views:

314

answers:

2

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.

A: 

If you only have a single object and you want to pass an array of objects (i.e. an array with a single element in it - your sole object), you use the @() syntax:

ps> $o = new-object mynamespace.myobj
ps> $thing.Method( @($o) )

-Oisin

x0n
A: 

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)
JasonMArcher