Question:
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.
1 2 3 4 5 6 7 8 9 10 11 |
$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:
1 2 3 4 5 |
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.
Answer:
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):
1 2 3 4 5 6 7 8 |
$computer = "rptdev" $uri = "http://$($computer)/ReportServer/ReportService.asmx?WSDL" $reporting = New-WebServiceProxy -uri $uri -UseDefaultCredential -namespace "ReportingWebService" [ReportingWebService.DataSource[]]$DataSources = $reporting.SetItemDataSources($DataSources) |