我正在尝试使用PowerShell调用SOAP API方法,但在向其传递参数时遇到问题。
我能够进行身份验证并拥有所有必需的权限。该方法可用。根据文档和WDSL,它有4个必需参数datetime
、datetime
、bool
、int
。我正在通过它们,但结果总是一样的错误:
Cannot find an overload for "GetFirstPageAlarms" and the argument count: "4".
At line:1 char:1
+ $alarmz = $Client.GetFirstPageAlarms([datetime]$endDate,[datetime]$en ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
以下是我的尝试:
# Connect to the API
$Client = New-WebServiceProxy -Uri $url -Credential get-credential
# Connects successfully
# Define parameters
$startDate = (get-date).AddDays(-2)
$endDate = get-date
$allUsers = $true
$maximumResultsPerPage = 10
# Call the method
$results = $Client.GetFirstPageAlarms([datetime]$endDate,[datetime]$endDate,[boolean]$True,[int]"5")
# Fails here.
# Alternative, also fails with same error
$Client.GetFirstPageAlarms("2020-11-01","2020-12-01","True","5")
# And another alternative failing
$Client.GetFirstPageAlarms([datetime]"2020-11-01",[datetime]"2020-12-01",[boolean]$True,[int]"5")
从谷歌搜索来看,Overload
错误似乎与所需参数的错误类型有关。我试图指定类型,但仍然失败。
我尝试了更多的东西,到处寻找信息,没有选择和想法了。我希望有人能帮忙。谢谢
方法的WSDL定义:
<xs:element name="GetFirstPageAlarms">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="startDate" type="xs:dateTime"/>
<xs:element minOccurs="0" name="endDate" type="xs:dateTime"/>
<xs:element minOccurs="0" name="allUsers" type="xs:boolean"/>
<xs:element minOccurs="0" name="maximumResultsPerPage" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
API文档链接:https://docs.logrhythm.com/docs/lrapi/soap-api-logrhythm-7-x-x/soap-api-reference-guide-logrhythm-7-x-x/soap-api-reference-alarmservice/soap-api-alarmservice-methods#SOAPAPIAlarmService,方法获取第一页警报
我想这已经解决了:
$client | get-member GetFirstPageAlarms
返回
TypeName : Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1ices_AlarmServiceBasicAuth_svc.AlarmService
Name : GetFirstPageAlarms
MemberType : Method
Definition : Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1ices_AlarmServiceBasicAuth_svc.AlarmSummaryDataResults GetFirstPageAlarms(datetime startDate, bool startDateSpecified, datetime
endDate, bool endDateSpecified, bool allUsers, bool allUsersSpecified, int maximumResultsPerPage, bool maximumResultsPerPageSpecified)
有一些隐藏的属性需要添加。出于某种原因,医生没有提到他们。
$Client.GetFirstPageAlarms([datetime]"2020-11-01",[bool]$true,[datetime]"2020-12-01",[bool]$true,[bool]$true,[bool]$true,[int]"5",[bool]$true)
出现新错误:
Exception calling "GetFirstPageAlarms" with "8" argument(s): "An error occurred when verifying security for the message."
At line:1 char:1
+ $Client.GetFirstPageAlarms([datetime]"2020-11-01",[bool]$true,[dateti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SoapHeaderException
但这可能是一个单独的问题,与作战手册中的问题无关。