[英]System.InvalidOperationException: Missing parameter error when trying to consume web service from vbscript
I have the code below to consume a web service using javascript. 我下面有使用JavaScript使用Web服务的代码。 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,
XmlNode
in this case, I get this error: 当我调用没有参数的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: 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
So basically my question is what I'm doing wrong? 所以基本上我的问题是我做错了什么? If you check the line where I populate the
strEnvelope
variable, I'm explicitly populating the XmlNode
parameter. 如果检查填充
strEnvelope
变量的行, strEnvelope
显式填充XmlNode
参数。 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 strEnvelope
variable value at the end of the first function), and get the value from this strEnvelope
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. 我使用Soap UI为该Web服务方法获取了Soap信封,然后转到日志(您可以看到我正在记录第一个函数末尾的
strEnvelope
变量值),并从此strEnvelope
变量获取值并将其放在Soap UI中,就可以正常工作,因此,我可以确认为此方法使用的Soap信封是可以的。 I suspect the issue might be related with the SetRequestHeader
property I'm using, but I'm not sure. 我怀疑问题可能与我使用的
SetRequestHeader
属性有关,但我不确定。
Can anyone help me here? 有人能帮我一下吗?
Note: I'm executing the vbscript within the same server that hosts the web service. 注意:我正在托管Web服务的同一台服务器中执行vbscript。 This is the response I get logged in Fiddler:
这是我在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()
I was able to solve it. 我能够解决。 The web service was always working if I invoked it from IE (when you open IIS, right click on the web service
.asmx
file, and click on browse), so I looked at the call in Fiddler and found out that the SOAP envelope that worked only had: XmlNode=<samples><sample>
如果我从IE调用了该Web服务,则该Web服务始终可以正常工作(当您打开IIS时,右键单击该Web服务
.asmx
文件,然后单击浏览),因此我查看了Fiddler中的调用,发现该SOAP信封仅适用于: XmlNode=<samples><sample>
instead of having the entire SOAP envelope I was using in my original post. 而不是拥有原始帖子中使用的整个SOAP信封。 So I found that when you see the service definition (when you open IIS, right click on the web service
.asmx
file, and click on browse), there are three examples, soap1.1
, soap1.2
and HTTP Post
, so in this scenario I had to use the HTTP Post
example. 所以我发现,当您看到服务定义时(打开IIS时,右键单击Web服务
.asmx
文件,然后单击浏览),有三个示例, soap1.1
, soap1.2
和HTTP Post
,因此在在这种情况下,我必须使用HTTP Post
示例。 So this is how the code looks now: 因此,现在的代码如下所示:
So this is how I populate the Envelope now: 因此,这就是我现在填充信封的方式:
Dim strEnvelope:strEnvelope = "XmlNode=" & SamplePlan
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.