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.
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)
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
Related
Consuming a simple webservice using powershell. It is supposed to return 2 values, but powershell only shows one. SOAPUI works fine, shows two values. If I don't pass as [ref] the call errors. Not sure why this is?
$URL = "https://nonpublic/wsdl/location"
$URI = New-Object System.Uri($URL);
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webproxy = New-WebServiceProxy -Uri $URI -Namespace webproxy-class ssl
## webservice to return two values related to passed value
$val = "ide-550"
$result = $webproxy.getinfo([ref]$val)
$result ## <-- only one value
EDIT: get member output - statustype getinfo(string [ref] val).
So i made a script that parses a .msg file in outlook and ommits the result. The whole scripts works except for when I receive an email from inside the network (we use Active Directory) is when i get a result similar to this: /O=Business/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=MIKEF
otherwise for emails outside the network I get email#email.com. I would like to to validate this this with regex that way it would take the name in the CN=" " and adds it to my #email.com
$MSGFILEPATH = '\\srv01\FTP\EmailtoSupportPortal\Testing'
$MSGCOMPLETED= '\\srv01\FTP\EmailtoSupportPortal\Testing\Completed'
Function MSGFiles {
Get-ChildItem $MSGFILEPATH -Filter *.msg|`
ForEach-Object{
$outlook = New-Object -comobject outlook.application
$msg = $outlook.CreateItemFromTemplate($_.FullName)
$body = $msg.Body
$SEM = $msg.SenderEmailAddress
$Subject = $msg.Subject
$SEM
}
}
MSGFiles
Check the MailItem.SenderEmailType property. If it is "EX", use MailItem.Sender.GetExchangeUser.PrimarySmtpAddress (be prepared to handle nulls/errors).
Otherwise use the SenderEmailAddress property the way you do that now.
I have a joomla template that has two styles. The name of the template is default, and the styles are cats and arts. is there a way to return the name of the current style in use.
the code below only return the name of the template
$template = $app->getTemplate();
if I do an echo $template; I get default. But what I would like to get, is whether I am using the style cats or the style arts
Thank you
The template object doesn't contain the name of the a templates style variations (as it's only really used for human administrators as a mnemonic).
The only way to tell which "style" is being used is to look at the id value of the template… this value will correspond to the one you see in the ID column of the "Template Manager - Styles" view.
// Get the Joomla Application
$app = JFactory::getApplication();
// Get the template
$template = $app->getTemplate(true);
// Echo the ID
echo $template->id;
If you really need the "name" I think you're probably making a design mistake, having said that you could try loading the style model for the $template->id and retrieving it that way. e.g. something like this (warning typed directly into SO, NOT TESTED!)
// Initialise some vars
$name = 'Style';
$prefix = 'TemplatesModel';
$config = array();
// Get the model
$templateStyleModel = JModelLegacy::getInstance($name, $prefix, $config);
// Load the specific style instance.
$templateStyleModel->load($template->id);
// Echo out the style name
echo $templateStyleModel->title;
$params = $app->getTemplate(true)->params;
Use $params->get() to get the particular style's params.
The solution look are looking for is:
$app = Factory::getApplication();
$template = $app->getTemplate(true);
$styleModel = new Joomla\Component\Templates\Administrator\Model\StyleModel();
$style = $styleModel->getItem($template->id);
$style->alias = Joomla\CMS\Filter\OutputFilter::stringURLSafe($style->title);
In PHP I can use this code:
$url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=$location1& destinations=$location2&mode=bicycling&language=en-EN&sensor=false";
$data = #file_get_contents($url);
$obj = json_decode($data);
$arr = (array)$obj;
to get an array of values that return the distance between 2 locations.
Is this kind of web interaction possible with VSTO? I have Googled high and low and nothing I search is giving me any results to work with.
Ergo, I think I am missing something.
I am using powershell to deploy our SSRS reports, but have come across an issue when deploying multiple reports.
$uri = "http:///Reportserver2008/reportservice2005.asmx"
$Proxy = New-WebServiceProxy -Uri $uri -Namespace SSRS.ReportingService2005 -UseDefaultCredential ;
$Proxy | gm "SetItemDataSources"
Which returns a method definition of:
System.Void SetItemDataSources(string Item, SSRS.ReportingService2005.DataSource[] DataSources)
If I duplicate the code above, the method definition changes the second time it is requested
e.g
$uri = "http:///Reportserver2008/reportservice2005.asmx"
$Proxy = New-WebServiceProxy -Uri $uri -Namespace SSRS.ReportingService2005 -UseDefaultCredential ;
$Proxy | gm "SetItemDataSources"
$Proxy = New-WebServiceProxy -Uri $uri -Namespace SSRS.ReportingService2005 -UseDefaultCredential ;
$Proxy | gm "SetItemDataSources"
Returns two different method definitions:
System.Void SetItemDataSources(string Item, SSRS.ReportingService2005.DataSource[] DataSources)
System.Void SetItemDataSources(string Item, SSRS.ReportingService2005.DataSource[], 0juuvurk, Ve...
Can anyone explain why the definition changes???
I have tried disposing $proxy after first request, Uri does not change
I am thinking I may have to pull out $proxy and only assign it once.
Any insight greatly appreciated!
You're right on with your instincts. Creating 2nd or 3rd proxies of web services can cause trouble, because the proxies get put into automatically generated namespaces. So proxying twice actually redoes a lot of work, and creates two very similar looking types in memory.
There are generally two ways to work with this sort of issue:
Use the -Namespace parameter to force the object into a namespace.
Use $proxy.GetType().Namespace to find the automatically generated base type
Hope this helps