0
我想通过Excel 2010中的VBA中的SOAP请求检索一些信息。我之前没有使用过这个,但是我确实做了一些搜索并调整了不同的代码与我认为应该工作,但我一直陷入相同的错误(没有SOAPAction标题)。我在SoapUI中尝试过WSDL,它的工作原理,所以我不确定我出错的地方。Excel 2010中的VBA中没有SOAPAction标题错误
我提出请求的WSDL:
http://www.banxico.org.mx/DgieWSWeb/DgieWS?WSDL
的错误我不断收到:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
<faultstring>no SOAPAction header!</faultstring>
<detail>
<ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">SERVAP9</ns2:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
我使用的VBA代码:
Option Explicit
Sub SOAP()
'Set and instantiate our working objects
Dim Req As Object
Dim sEnv As String
Dim Resp As New MSXML2.DOMDocument60
Set Req = CreateObject("MSXML2.XMLHTTP")
Set Resp = CreateObject("MSXML2.DOMDocument.6.0")
Req.Open "Post", "http://www.banxico.org.mx/DgieWSWeb/DgieWS?WSDL", False
'Create SOAP envelope for submission to the Web Service
sEnv = sEnv & "<soapenv:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ws=""http://ws.dgie.banxico.org.mx"">"
sEnv = sEnv & " <soapenv:Header/>"
sEnv = sEnv & " <soapenv:Body>"
sEnv = sEnv & " <ws:tiposDeCambioBanxico soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""/>"
sEnv = sEnv & " </soapenv:Body>"
sEnv = sEnv & "</soapenv:Envelope>"
' Send SOAP Request
Req.send (sEnv)
' Display results in MessageBox
'MsgBox Req.responseText
Resp.LoadXML Req.responseText
Debug.Print Req.responseText
'clean up code
Set Req = Nothing
Set Resp = Nothing
End Sub
尝试这两个建议后,我仍然收到同样的错误。 – Chance