By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

NEWBEE wishes to send xml data via the SOAP method

plumpnation
P: 16
Hello one and all.

I have recently been working outside of my field of expertise alot, and it is greatly distressing me. I have learned a small amount of php and actionscript, but now need to move into the realm of asp.

I have been supplied this script in asp classic by the web service administrator as an example, but i have no idea how to use it in conjunction with a html POST form.

1. Should the form be put within the same page?

2. How do i replace the values in the strAppData portion of the script with the POST ones entered into the fields of the form?

The asp is working as expected, it's just that it's not dynamic.

<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>11111111</BrokerID>" & vbcrlf
strAppData = strAppData & " <BrokerName>Tester Broker</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>Mr</Title>" & vbcrlf
strAppData = strAppData & " <FirstName>James</FirstName>" & vbcrlf
strAppData = strAppData & " <Surname>Bond</Surname>" & vbcrlf
strAppData = strAppData & " <Email>james@uni-exports.co.uk</Email>" & vbcrlf
strAppData = strAppData & " <Marital>S</Marital>" & vbcrlf
strAppData = strAppData & " <HomePhone>01923280000</HomePhone>" & vbcrlf
strAppData = strAppData & " <MobilePhone>07779876554</MobilePhone>" & vbcrlf
strAppData = strAppData & " <Address>" & vbcrlf
strAppData = strAppData & " <YearsAtAddress>0</YearsAtAddress>" & vbcrlf
strAppData = strAppData & " <MonthsAtAddress>0</MonthsAtAddress>" & vbcrlf
strAppData = strAppData & " <HouseNameNo>38</HouseNameNo>" & vbcrlf
strAppData = strAppData & " <Street>West Close</Street>" & vbcrlf
strAppData = strAppData & " <Locality />" & vbcrlf
strAppData = strAppData & " <Town>London</Town>" & vbcrlf
strAppData = strAppData & " <County>Greater London</County>" & vbcrlf
strAppData = strAppData & " <Postcode>HA3 5LR</Postcode>" & vbcrlf
strAppData = strAppData & " </Address>" & vbcrlf
strAppData = strAppData & " </MainApp>" & vbcrlf
strAppData = strAppData & " <Details>" & vbcrlf
strAppData = strAppData & " <LoanAmount>25000</LoanAmount>" & vbcrlf
strAppData = strAppData & " <LoanTerm>120</LoanTerm>" & vbcrlf
strAppData = strAppData & " <LoanPurpose>CA</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.centraltrust.co.uk/AWDWebService/awdservice.asmx"
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
With objHTTP
.Open "POST", strUrl, false
.SetRequestHeader "Host", "testserver.centraltrust.co.uk"
.SetRequestHeader "Content-Type", "text/xml; charset=utf-8"
.SetRequestHeader "SOAPAction", "http://www.centraltrust.co.uk/SendApplication"
.send strSOAP
Response.Write(.responseText)
End With
%>
<br>
<%
End If
%>
<form id="frmTest" name="frmTest"method="post">
<input type="submit" value="Test" name="cmdSubmit">
</form>
</body>
</html>

If anybody can spare any time at all, i'd really appreciate it.

Thanks again.
Sep 7 '06 #1
Share this Question
Share on Google+
4 Replies


plumpnation
P: 16
Just in case no one uses classic asp anymore, could i ask that someone help me with this asp.net version that i'm writing/compiling.

At present, this script writes an xml file elsewhere in the parent folder of my localhost. Obviously this is little help, as i need to send it to a web service using the SOAP method.

Does anyone know how I can change this script in order to do that?




<%@ Page language="vb"%>
<%@ Import Namespace="System.XML" %>
<html><head>

<script language="VB" runat="server" ID=Script1>




Sub btnWriteXML_OnClick(sender As Object, e As EventArgs)
Try


Dim enc as Encoding
'Create file, overwrite if exists
'enc is encoding object required by constructor
'It is null, so default encoding is used
Dim objXMLTW as new XMLTextWriter(Server.MapPath("loanPerson.xml"), enc)
objXMLTW.WriteStartDocument
'Top level (Parent element)
objXMLTW.WriteStartElement("CentralTrust")
objXMLTW.WriteStartElement("Ident")

objXMLTW.WriteStartElement("BrokerID")
objXMLTW.WriteString("11702258")
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("BrokerName")
objXMLTW.WriteString("Irelish Limited")
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("AppNo")
objXMLTW.WriteString("1234-TST")
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Trans")
objXMLTW.WriteString("SHORTAPPSUBMIT")
objXMLTW.WriteEndElement

'end ident
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Application")

objXMLTW.WriteStartElement("MainApp")

'Child elements, from request form
objXMLTW.WriteStartElement("FirstName")
objXMLTW.WriteString(Request("firstname"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Surname")
objXMLTW.WriteString(Request("surname"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Email")
objXMLTW.WriteString(Request("email"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Address")
objXMLTW.WriteString(Request("address"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Marital")
objXMLTW.WriteString(Request("marital"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("HomePhone")
objXMLTW.WriteString(Request("homephone"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("MobilePhone")
objXMLTW.WriteString(Request("mobilephone"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Address")

objXMLTW.WriteStartElement("YearsAtAddress")
objXMLTW.WriteString(Request("yearsataddress"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("MonthsAtAddress")
objXMLTW.WriteString(Request("monthsataddress"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("HouseNameNo")
objXMLTW.WriteString(Request("housenameno"))
objXMLTW.WriteEndElement


objXMLTW.WriteStartElement("Street")
objXMLTW.WriteString(Request("street"))
objXMLTW.WriteEndElement


objXMLTW.WriteStartElement("Locality")
objXMLTW.WriteString(Request("locality"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Town")
objXMLTW.WriteString(Request("town"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("County")
objXMLTW.WriteString(Request("county"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Postcode")
objXMLTW.WriteString(Request("postcode"))
objXMLTW.WriteEndElement

'end Address
objXMLTW.WriteEndElement

'end MainApp
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("Details")

objXMLTW.WriteStartElement("LoanAmount")
objXMLTW.WriteString(Request("loanamount"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("LoanTerm")
objXMLTW.WriteString(Request("loanterm"))
objXMLTW.WriteEndElement

objXMLTW.WriteStartElement("LoanPurpose")
objXMLTW.WriteString(Request("loanpurpose"))
objXMLTW.WriteEndElement

'end Details
objXMLTW.WriteEndElement

'end Application
objXMLTW.WriteEndElement

'end Central Trust
objXMLTW.WriteEndElement

objXMLTW.WriteEndDocument 'End Document
objXMLTW.Flush 'Write to file
objXMLTW.Close



Catch Ex as Exception

End Try
End Sub


</script>
</head>

<body>

<center><b>XML Text Reader/Text Writer Demo</b></center>

<form method="post" action="XML_DEMO.aspx" runat="server" ID=Form1>



<TD width="50%" valign = top>
Complete the fields below to create and display the XML file "loanPerson.xml&quot;
<p><strong>Applicant</strong>

<table><tr><td>

FirstName:</td>

<td><asp:Textbox id=firstname runat="server" width="200"
visible="True"></asp:Textbox></td></tr>
<tr>
<td>Surname: </td>
<td>

<asp:Textbox id="surname" runat="server" visible="True" width="200"/></td></tr>
<tr><td>
City: </td>
<td>
<asp:Textbox id=city runat="server" width="200"
visible="True"></asp:Textbox></td></tr>
<tr>
<td>
Homephone: </td>
<td>
<asp:Textbox id=homephone runat="server" width="200" visible="True"
MaxLength="20"></asp:Textbox></td></tr>
<tr><td>
Postcode: </td>
<td>
<asp:Textbox id=postcode runat="server" width="200"
visible="True" maxlength="8"></asp:Textbox></td></tr>


</table></p>
</TD>
</tr>
</table>
<p>&nbsp;</p>
<asp:Button id="btnWriteXML" text="Submit" OnClick="btnWriteXML_onClick" runat="server" />

</form>



</body></html>




Thankyou for reading, even if you can't help.
Sep 7 '06 #2

plumpnation
P: 16
I've got an answer to my own question. I'll post it in case anyone fancies knowing

in the classic asp script to add a variable from the form, which is in this case in the same page as the asp, you can probably have the asp as an form action page as well ) you add

& Request.Form(“yourFieldname”) &

so that a line of your code looks like

strAppData = strAppData & "<Title>” & Request.Form(“App1Title”) & “</Title>" & vbcrlf

similar to adding variable values in php ("stuff".$variable."stuff")

I don't think anyone would use this script these days, but you never know.

Good luck to all of you.
Sep 7 '06 #3

P: 34
Check out w3schools.com XML and SOAP section .There are lot of examples
Hope this helps u
Sep 8 '06 #4

plumpnation
P: 16
Check out w3schools.com XML and SOAP section .There are lot of examples
Hope this helps u

thankyou very much :)
Sep 8 '06 #5

Post your reply

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