Powershell needs to use Soap complexType to support hot service

I am writing a powershell script that will ping a soap web service every 10 minutes so that it is hot and lively, so performance will increase. We tried many methods in IIS with the application pool timeout and just created http req for wsdl. But it seems to us that we should make a real request that goes to the sql server, and idle for 90 minutes will make it slow for requirements.

I need to build a rather complex search object in order to be able to do an intelligent search that will store a cached and hot servicelayer. 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>` 

I am trying to use New-WebServiceProxy, which works so elegantly in this powershellguy example . I create my own objects like this one from technet .

The powershell code I've 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) 

The error message does not make sense to me. It sounds like this: 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 
+6
source share
2 answers

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

Here is a solution that works:

 #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) 
+6
source

Your original technique is correct, you just need to enable the -class parameter in New-WebServiceProxy. Leave the rest of your code as it is.

I had this exact problem while working with a PowerShell web service yesterday. I also worked on this, opening up an auto-generated namespace, but it seemed too hoarse for me.

Then I found the solution mentioned here: https://groups.google.com/d/msg/microsoft.public.windows.powershell/JWB5yueLtrg/k0zeUUxAkTMJ

+4
source

Source: https://habr.com/ru/post/925856/


All Articles