在 Powershell 中使用 Soap complexType 来保持 Soap 服务的热度 [英] In Powershell to consume a Soap complexType to keep a Soap service hot

查看:44
本文介绍了在 Powershell 中使用 Soap complexType 来保持 Soap 服务的热度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a powershell script that will ping a soap webservice every 10 min to keep it hot and alive so performance will increase. We have tryed numerous techniques in the IIS with application pool idle timeout and just making http req for the wsdl. But it seems that we have to make real request that goes down to the sql server else an idle for 90 min will make it to slow for the requirements.

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

I have to construct a rather complex search object to be able to make a smart search that will keep the servicelayer cached and hot. The Soap Request Should look like this:

<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>`

我尝试使用在 powershellguy 的这个例子.我构建 my自己的对象作为来自technet的示例.

I try to use the New-WebServiceProxy which work so elegantly in this example by powershellguy. I construct my own Objects as this example from technet.

到目前为止我尝试过的powershell代码是这样的:

The powershell code I tried so far is this:

$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)

错误消息对我来说没有意义.听起来像:无法将tcm.FundInput"类型的tcm.FundInput"值转换为tcm.FundInput"类型

The Error Message does not make sense to me. Its sounds like: 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 对象.但我放弃了,继续使用默认创建的疯狂长命名空间.

I followed the link that Christian (credit should go to him, but I do not know how to do that) gave and used the default namespace instead. So now I do not need to restart powershell everytime. Maybe there is another solution to kill the fundSrvc object after each call. But I gave up and went with using the default created crazy long namespace.

这是有效的解决方案:

#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)

这篇关于在 Powershell 中使用 Soap complexType 来保持 Soap 服务的热度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆