gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:47:49 25 4
gpt4 key购买 nike

我正在尝试使用 SOAP 从经典 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

最佳答案

以下解决方案是我的问题的答案。 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

我从 url 中去掉了“?wsdl”并稍微改变了信封,现在它可以工作了。我还删除了 SoapMethodName header 的设置。

关于.net - 如何使用 SOAP 从经典 ASP 调用 .Net Web 服务方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6781734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com