我一直在尝试使用VBA创建SOAP请求,但每次我得到一个空白的响应。请在下面找到代码。 WSDL网址:http://productavailabilityfeed.xxxx.com/Availability.svc?wsdl
Dim sURL As String
Dim sEnv As String
'Set and Instantiate our working objects
Set objHttp = CreateObject("MSXML2.XMLHTTP")
sURL = "http://productavailabilityfeed.xxxx.com/Product.svc/soap"
' we create our SOAP envelope for submission to the Web Service
'sEnv = "<?xml version=""1.0"" encoding=""utf-8""?>"
'sEnv = sEnv & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope"">"
sEnv = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:tem=""http://tempuri.org/"">"
sEnv = sEnv & " <soap:Header>"
sEnv = sEnv & " <soap:Body>"
sEnv = sEnv & " <tem:GetAccommodationByCode>"
sEnv = sEnv & " <!--Optional:-->"
sEnv = sEnv & " <tem:getAccommodationByCodeRequest>"
sEnv = sEnv & " <!--Optional:-->"
sEnv = sEnv & " <tem:credentials>"
sEnv = sEnv & " <!--Optional:-->"
sEnv = sEnv & " <tem:username>?</tem:username>"
sEnv = sEnv & "<!--Optional:-->"
sEnv = sEnv & "<tem:password>?</tem:password>"
sEnv = sEnv & "</tem:credentials>"
sEnv = sEnv & "<!--Optional:-->"
sEnv = sEnv & "<tem:accommodationCode>?</tem:accommodationCode>"
sEnv = sEnv & "<!--Optional:-->"
sEnv = sEnv & "<tem:imageSize></tem:imageSize>"
sEnv = sEnv & "<!--Optional:-->"
sEnv = sEnv & "<tem:interval></tem:interval>"
sEnv = sEnv & "</tem:getAccommodationByCodeRequest>"
sEnv = sEnv & "</tem:GetAccommodationByCode>"
sEnv = sEnv & "</soapenv:Body>"
sEnv = sEnv & "</soapenv:Envelope>"
'we invoke the web service
'use this code snippet to invoke a web service which requires authentication
objHttp.Open "GET", sURL, False
objHttp.setRequestHeader "Content-Type", "text/xml"
objHttp.setRequestHeader "SOAPAction", "http://tempuri.org/xxxx/GetAccommodationByCode"
objHttp.send sEnv
MsgBox objHttp.responseText
'clean up code
Set objHttp = Nothing
Set XMLDOC = Nothing
答案 0 :(得分:1)
你肯定有错误:
objHttp.Open "GET", sURL, False
应替换为:
objHttp.Open "POST", sURL, False
这个错误不会让你前进。纠正此错误后,您可能需要调试soap消息。所以,在你改变之后,你可以告诉我们它是如何发展的。