繁体   English   中英

System.InvalidOperationException:尝试从vbscript使用Web服务时缺少参数错误

[英]System.InvalidOperationException: Missing parameter error when trying to consume web service from vbscript

我下面有使用JavaScript使用Web服务的代码。 当我调用没有参数的Dummy方法并仅返回一个字符串时,代码运行良好,但是当我尝试调用具有单个参数的方法XmlNode时,出现此错误:

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

VBScript函数:

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: " &  Now
    Set oXML_Aux = CreateObject(DOMDocument)
    strEnvelope = "<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:tem=""http://tempuri.org/"">" _
       & " <soap:Header/>" _
       & " <soap:Body>" _
       & "   <tem:SyncSamplePlan_DCA>" _
       & "       <tem:XmlNode><![CDATA[" & SamplePlan & "]]></tem:XmlNode>" _
       & "    </tem:SyncSamplePlan_DCA>" _
       & " </soap:Body>" _
       & " </soap:Envelope>"

    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: " & strEnvelope
End Function

Sub HandleStateChange
    if(oXMLHTTP.readyState = 4) then
        dim szResponse: szResponse = oXMLHTTP.responseText

       call oXMLDoc.loadXML(szResponse)

       if (oXMLDoc.parseError.errorCode <> 0) then
           call msgbox(oXMLDoc.parseError.reason)
       else
           call msgbox(oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text)
       end if
   end If
End Sub

所以基本上我的问题是我做错了什么? 如果检查填充strEnvelope变量的行, strEnvelope显式填充XmlNode参数。 我使用Soap UI为该Web服务方法获取了Soap信封,然后转到日志(您可以看到我正在记录第一个函数末尾的strEnvelope变量值),并从此strEnvelope变量获取值并将其放在Soap UI中,就可以正常工作,因此,我可以确认为此方法使用的Soap信封是可以的。 我怀疑问题可能与我使用的SetRequestHeader属性有关,但我不确定。

有人能帮我一下吗?

注意:我正在托管Web服务的同一台服务器中执行vbscript。 这是我在Fiddler中登录的响应:

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

我能够解决。 如果我从IE调用了该Web服务,则该Web服务始终可以正常工作(当您打开IIS时,右键单击该Web服务.asmx文件,然后单击浏览),因此我查看了Fiddler中的调用,发现该SOAP信封仅适用于: XmlNode=<samples><sample>

而不是拥有原始帖子中使用的整个SOAP信封。 所以我发现,当您看到服务定义时(打开IIS时,右键单击Web服务.asmx文件,然后单击浏览),有三个示例, soap1.1soap1.2HTTP Post ,因此在在这种情况下,我必须使用HTTP Post示例。 因此,现在的代码如下所示:

因此,这就是我现在填充信封的方式:

Dim strEnvelope:strEnvelope = "XmlNode=" & SamplePlan 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM