Classic ASP Tutorial: How to do Soap Requests

Comments 15 Standard

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 = ""
strURL = ""

'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=""""  xmlns:SOAP-ENC=""""" _
& "        xmlns:xsi="""" xmlns:xsd="""">" _
& "    <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>" "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.


15 thoughts on “Classic ASP Tutorial: How to do Soap Requests

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s