lang="en-US"> Classic ASP Tutorial: How to do Soap Requests –, LLC

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


You may also like...

14 Responses

  1. Rob says:

    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. Curtis says:

    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.

    • Jade says:

      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.

  3. Ofir says:

    this was VERY HELPFUL

    thanks alot!

  4. Matt says:

    Omg. THANK. YOU!

  5. Steve says:

    excellent, you saved me unknown hours trying to figure this out. Thanks!!!

  6. I love you who ever you are! I was about ready to give up

  7. It is nice to know that there still exist Classic ASP Lovers!

  8. MURAT AY says:

    Thank you .. Helpful article ..

  9. Juan says:

    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.

  10. Sharif says:

    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.

  11. Jade says:

    strURL is the connection to the SOAP service and strNamespace is the SOAP request.

Leave a Reply