NEWBEE wishes to send xml data via the SOAP method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • plumpnation
    New Member
    • Sep 2006
    • 16

    NEWBEE wishes to send xml data via the SOAP method

    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>Callin g a webservice from classic ASP</title>
    </head>
    <body>
    <%

    If Not IsEmpty(Request .Form("cmdSubmi t")) Then
    strAppData = ""
    strAppData = strAppData & "<CentralTrust> "
    strAppData = strAppData & " <Ident>" & vbcrlf
    strAppData = strAppData & " <BrokerID>11111 111</BrokerID>" & vbcrlf
    strAppData = strAppData & " <BrokerName>Tes ter Broker</BrokerName>" & vbcrlf
    strAppData = strAppData & " <AppNo>1234-TST</AppNo>" & vbcrlf
    strAppData = strAppData & " <Trans>SHORTAPP SUBMIT</Trans>" & vbcrlf
    strAppData = strAppData & " </Ident>" & vbcrlf
    strAppData = strAppData & " <Application> " & vbcrlf
    strAppData = strAppData & " <MainApp>" & vbcrlf
    strAppData = strAppData & " <Title>Mr</Title>" & vbcrlf
    strAppData = strAppData & " <FirstName>Jame s</FirstName>" & vbcrlf
    strAppData = strAppData & " <Surname>Bond </Surname>" & vbcrlf
    strAppData = strAppData & " <Email>james@un i-exports.co.uk</Email>" & vbcrlf
    strAppData = strAppData & " <Marital>S</Marital>" & vbcrlf
    strAppData = strAppData & " <HomePhone>0192 3280000</HomePhone>" & vbcrlf
    strAppData = strAppData & " <MobilePhone>07 779876554</MobilePhone>" & vbcrlf
    strAppData = strAppData & " <Address>" & vbcrlf
    strAppData = strAppData & " <YearsAtAddress >0</YearsAtAddress> " & vbcrlf
    strAppData = strAppData & " <MonthsAtAddres s>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>Great er 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>250 00</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:Enve lope xmlns:soap=""ht tp://schemas.xmlsoap .org/soap/envelope/"" xmlns:xsi=""htt p://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""htt p://www.w3.org/2001/XMLSchema"">" & vbcrlf
    strSOAP = strSOAP & " <soap:Body>" & vbcrlf
    strSOAP = strSOAP & " <SendApplicatio n xmlns=""http://www.centraltrus t.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.cent raltrust.co.uk/AWDWebService/awdservice.asmx "
    Set objHTTP = Server.CreateOb ject("Msxml2.Se rverXMLHTTP")
    With objHTTP
    .Open "POST", strUrl, false
    .SetRequestHead er "Host", "testserver.cen traltrust.co.uk "
    .SetRequestHead er "Content-Type", "text/xml; charset=utf-8"
    .SetRequestHead er "SOAPAction ", "http://www.centraltrus t.co.uk/SendApplication "
    .send strSOAP
    Response.Write( .responseText)
    End With
    %>
    <br>
    <%
    End If
    %>
    <form id="frmTest" name="frmTest"m ethod="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.
  • plumpnation
    New Member
    • Sep 2006
    • 16

    #2
    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="Syst em.XML" %>
    <html><head>

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




    Sub btnWriteXML_OnC lick(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(S erver.MapPath(" loanPerson.xml" ), enc)
    objXMLTW.WriteS tartDocument
    'Top level (Parent element)
    objXMLTW.WriteS tartElement("Ce ntralTrust")
    objXMLTW.WriteS tartElement("Id ent")

    objXMLTW.WriteS tartElement("Br okerID")
    objXMLTW.WriteS tring("11702258 ")
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Br okerName")
    objXMLTW.WriteS tring("Irelish Limited")
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Ap pNo")
    objXMLTW.WriteS tring("1234-TST")
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Tr ans")
    objXMLTW.WriteS tring("SHORTAPP SUBMIT")
    objXMLTW.WriteE ndElement

    'end ident
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Ap plication")

    objXMLTW.WriteS tartElement("Ma inApp")

    'Child elements, from request form
    objXMLTW.WriteS tartElement("Fi rstName")
    objXMLTW.WriteS tring(Request(" firstname"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Su rname")
    objXMLTW.WriteS tring(Request(" surname"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Em ail")
    objXMLTW.WriteS tring(Request(" email"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Ad dress")
    objXMLTW.WriteS tring(Request(" address"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Ma rital")
    objXMLTW.WriteS tring(Request(" marital"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Ho mePhone")
    objXMLTW.WriteS tring(Request(" homephone"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Mo bilePhone")
    objXMLTW.WriteS tring(Request(" mobilephone"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Ad dress")

    objXMLTW.WriteS tartElement("Ye arsAtAddress")
    objXMLTW.WriteS tring(Request(" yearsataddress" ))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Mo nthsAtAddress")
    objXMLTW.WriteS tring(Request(" monthsataddress "))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Ho useNameNo")
    objXMLTW.WriteS tring(Request(" housenameno"))
    objXMLTW.WriteE ndElement


    objXMLTW.WriteS tartElement("St reet")
    objXMLTW.WriteS tring(Request(" street"))
    objXMLTW.WriteE ndElement


    objXMLTW.WriteS tartElement("Lo cality")
    objXMLTW.WriteS tring(Request(" locality"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("To wn")
    objXMLTW.WriteS tring(Request(" town"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Co unty")
    objXMLTW.WriteS tring(Request(" county"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Po stcode")
    objXMLTW.WriteS tring(Request(" postcode"))
    objXMLTW.WriteE ndElement

    'end Address
    objXMLTW.WriteE ndElement

    'end MainApp
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("De tails")

    objXMLTW.WriteS tartElement("Lo anAmount")
    objXMLTW.WriteS tring(Request(" loanamount"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Lo anTerm")
    objXMLTW.WriteS tring(Request(" loanterm"))
    objXMLTW.WriteE ndElement

    objXMLTW.WriteS tartElement("Lo anPurpose")
    objXMLTW.WriteS tring(Request(" loanpurpose"))
    objXMLTW.WriteE ndElement

    'end Details
    objXMLTW.WriteE ndElement

    'end Application
    objXMLTW.WriteE ndElement

    'end Central Trust
    objXMLTW.WriteE ndElement

    objXMLTW.WriteE ndDocument 'End Document
    objXMLTW.Flush 'Write to file
    objXMLTW.Close



    Catch Ex as Exception

    End Try
    End Sub


    </script>
    </head>

    <body>

    <center><b>XM L Text Reader/Text Writer Demo</b></center>

    <form method="post" action="XML_DEM O.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>Appl icant</strong>

    <table><tr><t d>

    FirstName:</td>

    <td><asp:Textbo x 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="btnWri teXML_onClick" runat="server" />

    </form>



    </body></html>




    Thankyou for reading, even if you can't help.

    Comment

    • plumpnation
      New Member
      • Sep 2006
      • 16

      #3
      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(“y ourFieldname”) &

      so that a line of your code looks like

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

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

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

      Good luck to all of you.

      Comment

      • teju
        New Member
        • Jul 2006
        • 34

        #4
        Check out w3schools.com XML and SOAP section .There are lot of examples
        Hope this helps u

        Comment

        • plumpnation
          New Member
          • Sep 2006
          • 16

          #5
          Originally posted by teju
          Check out w3schools.com XML and SOAP section .There are lot of examples
          Hope this helps u

          thankyou very much :)

          Comment

          Working...