我正在编写一个PowerShell脚本,每隔10分钟就会对一个soap webservice进行ping操作,以保持它的热度和活力,因此性能会提高。我们已经在IIS中尝试了许多技术,其中包括应用程序池空闲超时以及为wsdl创建http req。但似乎我们必须向sql服务器发出真正的请求,否则闲置90分钟会使其速度变慢。
我必须构建一个相当复杂的搜索对象,以便能够进行智能搜索,以保持服务层缓存和热。肥皂请求应如下所示:
<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
答案 0 :(得分:6)
我按照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)
答案 1 :(得分:4)
您的原始技术是正确的,您只需要在New-WebServiceProxy上包含-class参数。保留其余的代码。
我昨天使用PowerShell的web服务时遇到了这个问题。我也通过发现自动生成的命名空间来工作,但这对我的喜好感觉有点过于讨厌。
然后我找到了这里提到的解决方案:https://groups.google.com/d/msg/microsoft.public.windows.powershell/JWB5yueLtrg/k0zeUUxAkTMJ