Classic ASP & Soap: Request Example

September 2, 2009

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, simply change the namespace and url to send request somewhere else.

For this example you’ll need to pass an accurate username and password and in return you’ll 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>USERNAME</authuser>" _
& "            <authpass>PASSWORD</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

Entry Filed under: ASP, Code Snippets, Programming Languages, for ASP. Tags: , , , , , , , , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Cool Sites

Free Code

Game Developer

Game Engines

Game Jobs

Music & Sound

Second Life

Sprites

Lost In Oblivion

September 2009
M T W T F S S
« Aug   Oct »
 123456
78910111213
14151617181920
21222324252627
282930  

Top Posts

Recent Posts

Archives

Feeds