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

标签 soap powershell wsdl

我正在编写一个 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/

相关文章:

Powershell Select-Object 没有获得任何属性

wcf - F# wsdl 类型提供程序错误?

c# - 用另一个分部类覆盖分部类的默认构造函数

.net - WS 安全 header 无效 - IRS ACA SOAP 请求

powershell - 使用 CSV 文件通过 IP 地址从网络中提取计算机名称

java - 属性中的 JAX-WS 命名空间,而不是前缀

regex - Powershell特定字符与功能不匹配

grails - 在 Grails 中使用 WSDL

python - 使用spyne,尝试在同一元素中生成具有 XML 属性和字符串值的特定 SOAP 响应

java - 如何从 JAX-WS 类中提取 SOAP 头信息?