title: In Powershell to consume a Soap complexType to keep a Soap service hot
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;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/"&gt;
     &lt;soapenv:Body&gt;
       &lt;fund:Get&gt;
          &lt;!--Optional:--&gt;
          &lt;fund:inputDTO&gt;
             &lt;fund:Fund&gt;
                &lt;fund:Identity&gt;
                   &lt;fund:Isin&gt;SE9900558666&lt;/fund:Isin&gt;
                   &lt;fund:FundBaseCurrencyId&gt;SEK&lt;/fund:FundBaseCurrencyId&gt;
                &lt;/fund:Identity&gt;
             &lt;/fund:Fund&gt;
             &lt;fund:InputContext&gt;
                &lt;tcm:ExtChannelId&gt;Channelman&lt;/tcm:ExtChannelId&gt;
                &lt;tcm:ExtId&gt;Rubberduck&lt;/tcm:ExtId&gt;
                &lt;tcm:ExtPosReference&gt;Rubberduck&lt;/tcm:ExtPosReference&gt;
                &lt;tcm:ExtUser&gt;Rubberduck&lt;/tcm:ExtUser&gt;
                &lt;tcm:LanguageId&gt;809&lt;/tcm:LanguageId&gt;
             &lt;/fund:InputContext&gt;
          &lt;/fund:inputDTO&gt;
       &lt;/fund:Get&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;`
  </code></pre>
  
  <p>I try to use the New-WebServiceProxy which work so elegantly in <a href="http://thepowershellguy.com/blogs/posh/archive/2009/05/15/powershell-v2-get-weather-function-using-a-web-service.aspx" rel="nofollow">this example by powershellguy</a>. I construct <a href="http://social.technet.microsoft.com/wiki/contents/articles/7804.powershell-creating-custom-objects-en-us.aspx*/" rel="nofollow">my own Objects as this example from technet</a>. </p>
  
  <p>The powershell code I tried so far is this:
  </p>
  
  <pre><code>$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)
  </code></pre>
  
  <p>The Error Message does not make sense to me. Its sounds like: <code>Cannot convert the "tcm.FundInput" value of type "tcm.FundInput" to type "tcm.FundInput"</code></p>
  
  <pre><code>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 &lt;&lt;&lt;&lt; ($myFundGoofer)
      + CategoryInfo          : NotSpecified: (:) [], MethodException
      + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
  </code></pre>