如何使用SOAP从经典ASP调用.Net Web服务方法

cra*_*mmy 6 .net soap web-services asp-classic

我试图使用SOAP从Classic ASP调用.Net Web服务.我已经构建了以下代码作为测试,并继续返回一个400 Bad Request错误的空响应者.我做错了什么,或者这个问题可能在.Net方面?

'set up xmlhttp to checkout server
Dim oRequest
Set oRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")

'setting this option will allow ServerXMLHTTP to ignore the certificate errors it encounters.
oRequest.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS


' resolve, connect, send, receive - in milliseconds
oRequest.setTimeouts 10000, 10000, 10000, 10000

'set the URL
msURL = "[redacted]"

msSOAP = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
msSOAP = msSOAP & "<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">"
msSOAP = msSOAP & "<SOAP:Body>"
msSOAP = msSOAP & "<[Some Service] xmlns=""http://localhost"">"
msSOAP = msSOAP & "<MethodName>"
msSOAP = msSOAP & "<methodParam1>[some value]</methodParam1>"
msSOAP = msSOAP & "<methodParam2>[some value]</methodParam2>"
msSOAP = msSOAP & "<methodParam3>[some value]</methodParam3>"
msSOAP = msSOAP & "</MethodName>"
msSOAP = msSOAP & "</[Some Service]>"
msSOAP = msSOAP & "</SOAP:Body>"
msSOAP = msSOAP & "</soap12:Envelope>"

oRequest.Open "POST", msURL, False
oRequest.setRequestHeader "Content-Type", "text/xml"
oRequest.setRequestHeader "SOAPMethodName", "[MethodName]"
oRequest.setRequestHeader "SOAPAction", "[Some Url]"
oRequest.send msSOAP

Response.Write oRequest.ResponseBody
Run Code Online (Sandbox Code Playgroud)

cra*_*mmy 3

以下解决方案是我的问题的答案。Filburt,一旦我真正进行了一次良好的 SOAP 调用,我发现您的问题是高度合理的。类型和格式非常重要!

'set up xmlhttp to checkout server
Dim oRequest
Set oRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")

'setting this option will allow ServerXMLHTTP to ignore the certificate errors it encounters.
oRequest.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS

' resolve, connect, send, receive - in milliseconds
oRequest.setTimeouts 10000, 10000, 10000, 10000

'set the URL
msURL = "[Service Url]"

msSOAP = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
msSOAP = msSOAP & "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">"
msSOAP = msSOAP & "<s:Body>"
msSOAP = msSOAP & "<[MethodName] xmlns=""[Some Namespace]"">"
msSOAP = msSOAP & "<methodParam1>[Some value]</methodParam1>"
 msSOAP = msSOAP & "<methodParam2>[Some value]</methodParam2>"
 msSOAP = msSOAP & "<methodParam3>[Some value]</methodParam3>"
   msSOAP = msSOAP & "</MethodName>"
msSOAP = msSOAP & "</s:Body>"
msSOAP = msSOAP & "</s:Envelope>"

oRequest.Open "POST", msURL, False
oRequest.setRequestHeader "Content-Type", "text/xml"
oRequest.setRequestHeader "SOAPAction", "[Some Url]"
oRequest.send msSOAP
Run Code Online (Sandbox Code Playgroud)

我从网址中去掉了“?wsdl”,并稍微更改了信封,现在可以使用了。我还删除了 SoapMethodName 标头的设置。