I'm trying to create a function that uses New-WebServiceProxy
as a parameter, but I get an error. My function code:
function Execute-SOAPRequest () {
[CmdletBinding()]
Param
(
[Parameter(Position = 0, Mandatory = $true)]
[New-WebServiceproxy]$myService,
[Parameter(Position = 1, Mandatory = $true)]
[String]$url
)
write-host "Sending SOAP Request To Server: $url"
$myService.getUsers()
}
The error message:
At C:\myService.ps1:6 char:12 + [New-WebServiceproxy]$myService, + ~ Missing ] at end of attribute or type literal. At C:\myService.ps1:6 char:13 + [New-WebServiceproxy]$myService, + ~ Parameter declarations are a comma-separated list of variable names with optional initializer expressions. At C:\myService.ps1:6 char:13 + [New-WebServiceproxy]$myService, + ~ Missing ')' in function parameter list. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : EndSquareBracketExpectedAtEndOfAttribute
It doesn't like that dash-separated parameter's name [New-WebServiceproxy]. How to handle this?
New-WebServiceProxy
is a cmdlet that returns an object of typeWebServiceProxy
. You cannot use a cmdlet to specify the type of your parameter$myService
, useWebServiceProxy
instead.