make request to webservice through soap and get the response classic asp
asp-classic, web-services
Solution
yes:
the reason you are getting the 500 error ("expecting white space") is that your message is malformed. You have several xmlns declarations in the xml message, and because of a bug in your vbscript, there is no space between them. The result is invalid XML, and the server is returning the error because of it.
Also:
- You do not actually need the namespace declarations for the prefixes `env` and `xsd` in your message. They are never used.
- you do not need the `soap` prefix either. You can just set the default XML namespace.
- you can use single-quotes for the xmlns declarations. This can make the code more readable.
- you can insert newlines and whitespace in the xml message. This can also make the code more readable, specifically the code for the outbound message.
Using those suggested changes, Here is some code that works properly:
Dim msg, strStatus, strRetVal, postUrl
msg = "<?xml version='1.0' encoding='utf-8'?>" &_
"<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" & VbCrLf &_
" <Body>" & VbCrLf &_
" <getCustomer xmlns='http://abc.com/'>" & VbCrLf &_
" <storeUrl>www.abc.com/</storeUrl>" & VbCrLf &_
" <userKey>345</userKey>" & VbCrLf &_
" <batchSize>1</batchSize>" & VbCrLf &_
" <startNum>1</startNum>" & VbCrLf &_
" <customersFilter>firstname=John</customersFilter>"& VbCrLf &_
" <callBackURL></callBackURL>"& VbCrLf &_
" </getCustomer>" & VbCrLf &_
" </Body>" & VbCrLf &_
"</Envelope>"
Response.write("req=" & Server.HTMLEncode(msg) & "<br/>len=" & len(msg))
postUrl = "http://abc.com/cart.asmx?op=getCustomer"
Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlHTTP.open "POST", postUrl, false
xmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
'xmlHTTP.setRequestHeader "SOAPAction", "http://AvailReceive/AvailRq"
xmlHTTP.send msg
strStatus = xmlHTTP.Status
strRetval = xmlHTTP.responseText
set xmlHTTP = nothing
Response.write("<br/>")
Response.write("status=" & strStatus & "<br/>resp=" & strRetval)
But ...this code uncovers a runtime error in the .ASMX script.
resp=Error trying to get data from the store. Technical description: The remote name could not be resolved: 'www.abc.com'
If I modify the outgoing message to specify the hostname as `abc.com` instead of `www.abc.com`, then I get a reasonable-looking response.
Problem
I have webservices at the following link: http://abc.com/asmx I have made the request to webservice getcustomers using following code: ``` <% DIM PostData, strStatus, strRetVal, postUrl PostData = _ "<?xml version=""1.0"" encoding=""utf-8""?>" &_ "<soap:Envelope xmlns:env=""http://www.w3.org/2001/XMLSchema-instance"" &_ "xmlns:xsd='http://www.w3.org/2001/XMLSchema'" &_ "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_ "<soap:Body>" &_ " <getCustomer xmlns=""http://3dcart.com/"">" &_ "<storeUrl>www.abc.stores.com/</storeUrl>" &_ "<userKey>sdfsf</userKey>" &_ "<batchSize>1</batchSize>" &_ "<startNum>1</startNum>" &_ "<customersFilter>firstname=John</customersFilter>"&_ "<callBackURL></callBackURL>"&_ "</getCustomer>"&_ "</soap:Body>" &_ "</soap:Envelope>" response.write("req=" & Server.HTMLEncode(PostData) & "<br/>len=" & len(PostData)) postUrl = "http://abc.com/cart.asmx?op=getCustomer" Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") xmlHTTP.open "POST", postUrl, false xmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 'xmlHTTP.setRequestHeader "SOAPAction", "http://AvailReceive/AvailRq" xmlHTTP.send PostData strStatus = xmlHTTP.Status strRetval = xmlHTTP.responseText set xmlHTTP = nothing response.write("<br/>") response.write("status=" & strStatus & "<br/>resp=" & strRetval) %> ``` But i am getting error: resp=soap:ReceiverServer was unable to process request. ---> 'http' is an unexpected token. Expecting white space. Line 1, position 163. can you please advise why am i getting this error what is the solution to it.