472,107 Members | 1,221 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,107 software developers and data experts.

continuing the classic asp to web service saga: parse the response

plumpnation
I have now got this bulky piece of script working, it reads the form correctly, which sends the request to the web service using SOAP. It conforms to their DTD and the web service then responds and sends an xml document back to the page.

I would very much like the contents of the form to be entered into an sql database as it is sent to the web service, as their reply does not contain the full details filled into the form.

Aside from the response xml looking ugly written at the top of the html page, can anyone help me in my quest to open a success or failure page based upon the response xml recieved in the browser. i.e. can i parse it, picking out the SUCCESS or FAILURE text and use this info to forward to a new page?

<html>
<head>
<title>Calling a webservice from classic ASP</title>
</head>
<body>
<%

If Not IsEmpty(Request.Form("cmdSubmit")) Then
strAppData = ""
strAppData = strAppData & "<CentralTrust>"
strAppData = strAppData & " <Ident>" & vbcrlf
strAppData = strAppData & " <BrokerID>XXXXXXXX</BrokerID>" & vbcrlf
strAppData = strAppData & " <BrokerName>XXXXXXXXX</BrokerName>" & vbcrlf
strAppData = strAppData & " <AppNo>1234-TST</AppNo>" & vbcrlf
strAppData = strAppData & " <Trans>SHORTAPPSUBMIT</Trans>" & vbcrlf
strAppData = strAppData & " </Ident>" & vbcrlf
strAppData = strAppData & " <Application>" & vbcrlf
strAppData = strAppData & " <MainApp>" & vbcrlf
strAppData = strAppData & " <Title>" & Request.Form("title") & "</Title>" & vbcrlf
strAppData = strAppData & " <FirstName>" & Request.Form("firstname") & "</FirstName>" & vbcrlf
strAppData = strAppData & " <Surname>" & Request.Form("surname") & "</Surname>" & vbcrlf
strAppData = strAppData & " <Email>" & Request.Form("email") & "</Email>" & vbcrlf
strAppData = strAppData & " <Marital>" & Request.Form("marital") & "</Marital>" & vbcrlf
strAppData = strAppData & " <HomePhone>" & Request.Form("homephone") & "</HomePhone>" & vbcrlf
strAppData = strAppData & " <MobilePhone>" & Request.Form("mobilephone") & "</MobilePhone>" & vbcrlf
strAppData = strAppData & " <Address>" & vbcrlf
strAppData = strAppData & " <YearsAtAddress>" & Request.Form("yearsataddress") & "</YearsAtAddress>" & vbcrlf
strAppData = strAppData & " <MonthsAtAddress>" & Request.Form("monthsataddress") & "</MonthsAtAddress>" & vbcrlf
strAppData = strAppData & " <HouseNameNo>" & Request.Form("housenameno") & "</HouseNameNo>" & vbcrlf
strAppData = strAppData & " <Street>" & Request.Form("street") & "</Street>" & vbcrlf
strAppData = strAppData & " <Locality />" & vbcrlf
strAppData = strAppData & " <Town>" & Request.Form("town") & "</Town>" & vbcrlf
strAppData = strAppData & " <County>" & Request.Form("county") & "</County>" & vbcrlf
strAppData = strAppData & " <Postcode>" & Request.Form("postcode") & "</Postcode>" & vbcrlf
strAppData = strAppData & " </Address>" & vbcrlf
strAppData = strAppData & " </MainApp>" & vbcrlf
strAppData = strAppData & " <Details>" & vbcrlf
strAppData = strAppData & " <LoanAmount>" & Request.Form("loanamount") & "</LoanAmount>" & vbcrlf
strAppData = strAppData & " <LoanTerm>" & Request.Form("loanterm") & "</LoanTerm>" & vbcrlf
strAppData = strAppData & " <LoanPurpose>" & Request.Form("loanpurpose") & "</LoanPurpose>" & vbcrlf
strAppData = strAppData & " </Details>" & vbcrlf
strAppData = strAppData & " </Application>" & vbcrlf
strAppData = strAppData & "</CentralTrust>" & vbcrlf

strSOAP = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbcrlf
strSOAP = strSOAP & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" & vbcrlf
strSOAP = strSOAP & " <soap:Body>" & vbcrlf
strSOAP = strSOAP & " <SendApplication xmlns=""http://www.centraltrust.co.uk"">" & vbcrlf
strSOAP = strSOAP & " <appString>" & Replace(Replace(strAppData, "<", "&lt;"), ">", "&gt;") & "</appString>" & vbcrlf
strSOAP = strSOAP & " </SendApplication>" & vbcrlf
strSOAP = strSOAP & " </soap:Body>" & vbcrlf
strSOAP = strSOAP & "</soap:Envelope>" & vbcrlf

strURL = "http://testserver.mywebservice.co.uk/WebService/awservice.asmx"
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
With objHTTP
.Open "POST", strUrl, false
.SetRequestHeader "Host", "testserver.mywebservice.co.uk"
.SetRequestHeader "Content-Type", "text/xml; charset=utf-8"
.SetRequestHeader "SOAPAction", "http://www.centraltrust.co.uk/SendApplication"
.send strSOAP
Response.Write(.responseText)'this is the responded xml that I wish to use for redirection
End With
%>
<br>
<%
End If
%>

THIS IS THE FORM THAT NEEDS NOT ONLY TO GO TO THE ABOVE ASP TO BE INSERTED INTO THE XML FOR THE WEB SERVICE SOAP REQUEST, BUT ALSO NEEDS TO BE INPUTTED INTO A SQL DATABASE

<form id="frmTest" name="frmTest"method="post">
<p>
<label></label>
</p>
<table width="171" border="1">
<tr>
<td width="161" align="right"><p>title:
<label>
<select name="title" id="title">
<option value="Mr" selected>mr</option>
<option value="Mrs">mrs</option>
<option value="Miss">miss</option>
<option value="Ms">ms</option>
<option value="Dr">dr</option>
</select>
</label>
</p>
<p>firstname:
<input name="firstname" type="text" id="firstname" maxlength="50">

surname:
<input name="surname" type="text" id="surname" maxlength="50">
email:
<input name="email" type="text" id="email">
marital status:
<label>
<select name="marital" id="marital">
<option value="S" selected>single</option>
<option value="M">married</option>
<option value="D">divorced</option>
<option value="C">co-habiting</option>
<option value="W">widow</option>
<option value="I">widower</option>
</select>
</label>
<label> </label>
hometelno:
<input name="homephone" type="text" id="homephone">
mobile tel. no:
<input name="mobilephone" type="text" id="mobilephone">
years at address:
<input name="yearsataddress" type="text" id="yearsataddress">
</p>
<p>months at address: </p>
<p>
<input name="monthsataddress" type="text" id="monthsataddress">
</p>
<p>
house name or no:
<input name="housenameno" type="text" id="housenameno">
street:
<input name="street" type="text" id="street">
town:
<input name="town" type="text" id="town">
county:
<input name="county" type="text" id="county">
postcode:
<input name="postcode" type="text" id="postcode">
loan amount applying for:
<input name="loanamount" type="text" id="loanamount">
loanterm:
<input name="loanterm" type="text" id="loanterm">
purpose for loan:
<label>
<select name="loanpurpose" id="loanpurpose">
<option value="CA" selected>Car</option>
<option value="DC">Debt Consolidation</option>
<option value="CD">Consumer Durables</option>
<option value="HO">Holiday</option>
<option value="HI">Home Improvements</option>
<option value="OT">Other</option>
</select>
</label>
</p></td>
</tr>
</table>
<p>
<label></label>
<input type="submit" value="Submit Application" name="cmdSubmit">
</p>
</form>
</body>
</html>



Any help would be sorely appreciated. I will keep on it, and if I find an answer, will post it up.
Sep 8 '06 #1
2 3262
this is the returned xml from the web service. I need to write a portion of asp within the above script to do something IF the ResponseType is SUCCESS or FAILURE.

<document>
<Ident>
<BrokerID>14562132</BrokerID>
<AppNo>1234-TST </AppNo>
<Trans>RESPONSE</Trans>
</Ident>
<Application>
<Details>
<ResponseType>SUCCESS</ResponseType>
<OurID>08/09/2006 04:22:47</OurID>
</Details>
</Application>
</document>

Thankyou for your time. Remember I am writing in classic asp.

Nice one guys :)
Sep 8 '06 #2
found out.

use the (inStr) command to find out where it lies and then perhaps the (Mid) command to write the if function.

Technical jargon is not my speciality so forgive me if i've used the wrong terminology.

You could either say

if the reply from the inStr is more than 0, then you could assume that the reply is saying SUCCESS. (Look at the returned XML above.)

Response.Write InStr(yourSoapReplyString,"SUCCESS")

Or you could include the inStr value in the mid command to make sure the script starts reading the returned xml in the correct format.

If Mid(sQuerystring, InStr(sQueryString,"SUCCESS"), 7) = "SUCCESS" Then

This will reply a value. You could use the response value to determine what happens next.
Sep 18 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Julian Hershel | last post: by
5 posts views Thread by Mark | last post: by
2 posts views Thread by shadow.demon | last post: by
1 post views Thread by lambelly | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.