gpt4 book ai didi

soap - 在 Powershell 中使用 Soap complexType 来保持 Soap 服务的热度

转载 作者:行者123 更新时间:2023-12-04 14:03:20 29 4
gpt4 key购买 nike

我正在编写一个 powershell 脚本,它将每 10 分钟 ping 一次soap web 服务,以使其保持活跃状态​​,从而提高性能。我们已经在 IIS 中尝试了多种技术,应用程序池空闲超时和只是为 wsdl 制作 http req。但似乎我们必须向 sql server 发出真正的请求,否则 90 分钟的空闲时间会使其变慢以满足要求。

我必须构建一个相当复杂的搜索对象才能进行智能搜索,以保持服务层缓存和热。 Soap 请求应如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fund="http://www.example.com/cmw/fff/fund" xmlns:tcm="http://www.example.com/cmw/fff/">
<soapenv:Body>
<fund:Get>
<!--Optional:-->
<fund:inputDTO>
<fund:Fund>
<fund:Identity>
<fund:Isin>SE9900558666</fund:Isin>
<fund:FundBaseCurrencyId>SEK</fund:FundBaseCurrencyId>
</fund:Identity>
</fund:Fund>
<fund:InputContext>
<tcm:ExtChannelId>Channelman</tcm:ExtChannelId>
<tcm:ExtId>Rubberduck</tcm:ExtId>
<tcm:ExtPosReference>Rubberduck</tcm:ExtPosReference>
<tcm:ExtUser>Rubberduck</tcm:ExtUser>
<tcm:LanguageId>809</tcm:LanguageId>
</fund:InputContext>
</fund:inputDTO>
</fund:Get>
</soapenv:Body>
</soapenv:Envelope>`

我尝试使用在 this example by powershellguy 中工作得如此优雅的 New-WebServiceProxy .我构造 my own Objects as this example from technet .

到目前为止,我尝试过的 powershell 代码是这样的:
$fundSrvc = New-WebServiceProxy -uri http://myColdServer:82/WSFund.svc?wsdl -NameSpace "tcm"
# all the type are now defined since we called New-WebServiceProxy they are prefixed
# with ns tcm
[tcm.FundInput] $myFundGoofer = new-object tcm.FundInput
[tcm.Fund] $myFund = new-object tcm.Fund
[tcm.Context] $myInputContext = new-object tcm.Context
[tcm.FundIdentity] $myFundIdentity = New-Object tcm.FundIdentity
# Use these commands to get member of the objects you want to investigat
# $myFundGoofer |Get-Member
# $myFund |Get-Member
# $myInputContext |Get-Member
# $myFundIdentity |Get-Member
$myFundIdentity.Isin="SE9900558666"
$myFundIdentity.FundBaseCurrencyId="SEK"
$myInputContext.ExtChannelId="ChannelMan"
$myInputContext.ExtId="RubberDuck"
$myInputContext.ExtPosReference="RubberDuck"
$myInputContext.ExtUser="RubberDuck"
$myInputContext.LanguageId="809"
$myFund.Identity=$myFundIdentity

$myFundGoofer.Fund = $myFund
$myFundGoofer.InputContext = $myInputContext

#Tada
$fundSrvc.Get($myFundGoofer)

错误消息对我来说没有意义。它听起来像: Cannot convert the "tcm.FundInput" value of type "tcm.FundInput" to type "tcm.FundInput"
Cannot convert argument "0", with value: "tcm.FundInput", for "Get" to type "tcm.FundInput": "Cannot convert the "tcm.FundInput" value of type "tcm.FundInput" to type "tcm.FundInput"."
At C:\scripts\Service-TestTCM6.ps1:31 char:14
+ $fundSrvc.Get <<<< ($myFundGoofer)
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

最佳答案

我遵循了 Christian(应该归功于他,但我不知道该怎么做)给出的链接,并使用了默认命名空间。所以现在我不需要每次都重新启动 powershell。也许有另一种解决方案可以在每次调用后杀死 fundSrvc 对象。但我放弃了,继续使用默认创建的疯狂长命名空间。

这是有效的解决方案:

#note no -Namespace argument  
$fundSrvc = New-WebServiceProxy -uri "http://myColdServer/WSFund.svc?wsdl"


#get autogenerated namespace
$type = $fundSrvc.GetType().Namespace
$myFundGooferDt = ($type + '.FundInput')
$myFundDt = ($type + '.Fund')
$myInputContextDt = ($type + '.Context')
$myFundIdentityDt = ($type + '.FundIdentity')
# Create the Objects needed
$myFundGoofer = new-object ($myFundGooferDt)
$myFund = new-object ($myFundDt)
$myInputContext = new-object ($myInputContextDt)
$myFundIdentity = New-Object $myFundIdentityDt
# Assign values
$myFundIdentity.Isin="SE9900558666"
$myFundIdentity.FundBaseCurrencyId="SEK"
$myInputContext.ExtChannelId="ChannelMan"
$myInputContext.ExtId="RubberDuck"
$myInputContext.ExtPosReference="RubberDuck"
$myInputContext.ExtUser="RubberDuck"
$myInputContext.LanguageId="809"
$myFund.Identity=$myFundIdentity

$myFundGoofer.Fund = $myFund
$myFundGoofer.InputContext = $myInputContext

#Tada
$fundSrvc.Get($myFundGoofer)

关于soap - 在 Powershell 中使用 Soap complexType 来保持 Soap 服务的热度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12516512/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com