Classic ASP Tutorial: How to do Soap Requests
So I was having a helluva time trying to get this working. I was finally able to muck around and get a setup that would connect to SOAP at CapWiz like it’s supposed to. Almost all the examples I found were for AJAX and .Net. This code will work for classic ASP. This example is setup to connect to CapWiz. If you want to use it for some other service simply change the namespace and url.
In order for this code to work as-is you’ll need a CapWiz account. If you run this code “as-is” you’ll send a SOAP request to CapWiz and get demographics from the elected individuals in Fairfax, VA in XML format.
<% Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0") Dim strRequest, strResult, strFunction, strURL, strNamespace 'URL to SOAP namespace and connection URL strNamespace = "http://capwiz.com/CapWiz/SOAP/Services" strURL = "http://capwiz.com/soap/" 'function you want to call strFunction = "get_demographics_electeddistricts" 'strFunction = "test" 'no parameters required strRequest ="<?xml version=""1.0"" encoding=""utf-8""?>" _ & "<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/""" _ & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" _ & " <SOAP-ENV:Body>" _ & " <m:" & strFunction & " xmlns:m=""" & strNamespace & """>" _ & " <authuser>YOUR_USERNAME_HERE</authuser>" _ & " <authpass>YOUR_PASSWORD_HERE</authpass>" _ & " <street>2751 Prosperity Ave</street>" _ & " <city>Fairfax</city>" _ & " <state>VA</state>" _ & " <zip5>22031</zip5>" _ & " </m:" & strFunction & ">" _ & " </SOAP-ENV:Body>" _ & "</SOAP-ENV:Envelope>" objXMLHTTP.open "post", "" & strURL & "", False objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8" objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest) objXMLHTTP.setRequestHeader "SOAPAction", strNamespace & "#" & strFunction 'send the request and capture the result Call objXMLHTTP.send(strRequest) strResult = objXMLHTTP.responseText 'display the XML response.write strResult %>
I did use one reference from Experts Exchange.
get_demographics_electeddistricts
This post helped me out a lot in making a call to a SOAP web service. I’m getting a XML response back (which is good).
What I am trying to figure out now is how to parse that XML response and grab the text for a particular element as, in my case, that element returns a sales tax rate and I need to isolate just that element’s value. Can anyone point me in the right direction? I can post the XML that is returned from the web service if that’s helpful.
Thanks again for getting me started with this. It’s an area that I have not worked with much yet.
What you need to do is write code or a function that parses the XML. If you want some free code you can just grab off the net I would suggest this blog >> http://usefulscripts.wordpress.com/2008/05/14/parsing-xml-file-in-asp/
I know this post is dated but I was wondering where you got the API information for Capwiz. As far as I can tell, this post is the only evidence on the entire internet that it actually exists.
You need to contact your CapWiz representative. In some cases you have to show proof of having certain security measures in place before they’ll release the API and documentation to you.
this was VERY HELPFUL
thanks alot!
Omg. THANK. YOU!
excellent, you saved me unknown hours trying to figure this out. Thanks!!!
I love you who ever you are! I was about ready to give up
Lol glad I could help.
It is nice to know that there still exist Classic ASP Lovers!
Thank you .. Helpful article ..
Thanks a lot. It was very helpful also to me.
#10: It’s not about ASP love, but there are a lot of classic ASP webapps still out there that need to be maintained, but if we talk about love, i’m in love with Ruby 🙂 very very far away from classic ASP.
Hi, thanks a lot for this article. Probably this a stupid question, but i can not figure out and therefore i am getting an error. what is the difference between strNamespace & strURL here?
For example for my .net web Service method URL is “http://localhost:57004/FFS/Service.asmx?op=HelloWorld” then what will be value of strNamespace & strURL?
Please help.
strURL is the connection to the SOAP service and strNamespace is the SOAP request.