0

我正在尝试创建一个New-WebServiceProxy用作参数的函数,但出现错误。我的功能代码:

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()
}

错误信息:

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

它不喜欢用破折号分隔的参数名称 [New-WebServiceproxy]。如何处理?

4

1 回答 1

0

New-WebServiceProxy是一个返回类型对象的 cmdlet WebServiceProxy。您不能使用 cmdlet 来指定参数的类型,请$myService改用WebServiceProxy

于 2020-06-15T12:29:35.133 回答