title: System.InvalidOperationException: Missing parameter error when trying to consume web service from vbscript
body: <p>I have the code below to consume a web service using javascript. The code works well when I invoke a Dummy method that has no parameters and just returns a string, but when I attempt to invoke a method that has a single parameter, <code>XmlNode</code> in this case, I get this error:</p>
  
  <pre><code>System.InvalidOperationException: Missing parameter: XmlNode.
     at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
     at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)
     at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
     at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
  </code></pre>
  
  <p>VBScript function:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Function ConsumeWebService(SamplePlan)
      Dim oXML_Aux
  
      Dim strURL
      Dim logger:Set logger = New EMR_Logging
      Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
      Dim strEnvelope
  
      logger.LogInfo "Invoking ConsumeWebService - StartTime: " &amp;  Now
      Set oXML_Aux = CreateObject(DOMDocument)
      strEnvelope = "&lt;soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:tem=""http://tempuri.org/""&gt;" _
         &amp; " &lt;soap:Header/&gt;" _
         &amp; " &lt;soap:Body&gt;" _
         &amp; "   &lt;tem:SyncSamplePlan_DCA&gt;" _
         &amp; "       &lt;tem:XmlNode&gt;&lt;![CDATA[" &amp; SamplePlan &amp; "]]&gt;&lt;/tem:XmlNode&gt;" _
         &amp; "    &lt;/tem:SyncSamplePlan_DCA&gt;" _
         &amp; " &lt;/soap:Body&gt;" _
         &amp; " &lt;/soap:Envelope&gt;"
  
      Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
      oXMLHTTP.onreadystatechange = GetRef("HandleStateChange")
  
      strURL = "http://ocn-da2.lsecmes.rvoaustin.local/GNE_OCN_Webparts/QC_Sampling_Plan_Import/QC_Sample_Plan_Import.asmx/SyncSamplePlan_DCA"
      call oXMLHTTP.open("POST", strURL, False)
  
      call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded") 'orig
      oXML_Aux.loadXml strEnvelope
  
      call oXMLHTTP.send(oXML_Aux.xml)
      logger.LogInfo "Invoking Web Service- strSoapEnvelope: " &amp; strEnvelope
  End Function
  
  Sub HandleStateChange
      if(oXMLHTTP.readyState = 4) then
          dim szResponse: szResponse = oXMLHTTP.responseText
  
         call oXMLDoc.loadXML(szResponse)
  
         if (oXMLDoc.parseError.errorCode &lt;&gt; 0) then
             call msgbox(oXMLDoc.parseError.reason)
         else
             call msgbox(oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text)
         end if
     end If
  End Sub
  </code></pre>
  
  <p>So basically my question is what I'm doing wrong? If you check the line where I populate the <code>strEnvelope</code> variable, I'm explicitly populating the <code>XmlNode</code> parameter. I took the Soap envelope for this web service method using Soap UI, and if go to the logs (you can see that I'm logging the <code>strEnvelope</code> variable value at the end of the first function), and get the value from this <code>strEnvelope</code> variable and put it in Soap UI, it works with no issues, so with this I can confirm that the Soap envelope I'm using for this method is ok. I suspect the issue might be related with the <code>SetRequestHeader</code> property I'm using, but I'm not sure.</p>
  
  <p>Can anyone help me here?</p>
  
  <p>Note: I'm executing the vbscript within the same server that hosts the web service.
  This is the response I get logged in Fiddler:</p>
  
  <pre><code>HTTP/1.1 500 Internal Server Error
  Cache-Control: private
  Content-Type: text/plain; charset=utf-8
  Server: Microsoft-IIS/7.0
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Wed, 17 Sep 2014 21:48:23 GMT
  Connection: close
  Content-Length: 404
  
  System.InvalidOperationException: Missing parameter: XmlNode.
     at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
     at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)
     at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
     at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
  </code></pre>