ASP
  Home arrow ASP arrow Page 2 - An Introduction To XML SOAP Using ASP and ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

An Introduction To XML SOAP Using ASP and VB6
By: ComponentSource Team
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 27
    2002-08-12

    Table of Contents:
  • An Introduction To XML SOAP Using ASP and VB6
  • Step By Step
  • The Server
  • VB Client Code
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    An Introduction To XML SOAP Using ASP and VB6 - Step By Step


    (Page 2 of 5 )

    As we know, SOAP is a call-response mechanism, which operates in a client-server paradigm. The client (your application) makes a call to the server (a web server, somewhere on the internet), passing in parameters; and the server provides a response. Both call and response are transported in the form of XML documents. Therefore, to build our own example SOAP system, we need both a client and a server – a caller and a responder.

    The example we will follow is a very simple one: we will build a service that will calculate the tax due on a sales transaction. In traditional VB terms well will create a function with the following definition:

    Public Function GetSalesTax(ByVal pSalesTotal As Double) as Double
    GetSalesTax = pSalesTotal * 0.04
    End Function


    Crude, but effective (if you live in a state where the sales tax rate is 4%!)

    This function defines a method name (GetSalesTax), a parameter (pSalesTotal – representing the total value of the sale) and a return value (the result of the function). In more traditional object-oriented terms, we might think of pSalesTotal as an "IN" parameter, and the GetSalesTax result as an "OUT" parameter. Quite straightforwardly: sales-total in; sales-tax out. A SOAP service can be thought of in terms of "IN" and "OUT" parameters – the client passes "IN" parameters to the server, and then receives the "OUT" parameters in return. So, in order to create our SOAP service, we need a server that will listen for requests to GetSalesTax, accompanied by "IN" parameters, and which will respond with "OUT" parameters, indicating the correct tax amount. Let's start with the client – the caller. How do we call the SOAP service to make our request.

    The Client
    In traditional VB terms, our request to the GetSalesTax function described above, would be something such as:

    dblSalesTax = GetSalesTax(100)

    Returning a value of $4.

    If the GetSalesTax function was contained within an external object, such as an MTS server, then the call would need to reference the server DLL:

    Dim objTax As New CTaxCalc

    dblSalesTax = objTax.GetSalesTax(100


    In a SOAP system the call is little different, only the request is formatted as an XML document, which is passed up to the server. The appropriate document contains the same details as the MTS call –a method to call, and the parameter name and value.

    <GetSalesTax>
    <SalesTotal>100</SalesTotal>
    <GetSalesTax>


    In order to ensure that the server can correctly identify and decrypt this method call, it is wrapped up in a larger document, called a SOAP envelope, which references the universal name-space of the SOAP envelope standard.

    <SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1">
    <SOAP:Header></SOAP:Header>
    <SOAP:Body>
    <GetSalesTax>
    <SalesTotal>100</SalesTotal>
    <GetSalesTax>
    </SOAP:Body>
    </SOAP:Envelope>


    Finally, to complete our SOAP request document, we will add a name-space reference to our method call, which points to the object which contains the method – the equivalent of the object declaration (Dim objTax As New CTaxCalc) in our MTS method call.

    <SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1">
    <SOAP:Header></SOAP:Header>
    <SOAP:Body>
    <m:GetSalesTax xmlns:m="urn:myserver/soap:TaxCalc">
    <SalesTotal>100</SalesTotal>
    </m:GetSalesTax>
    </SOAP:Body>
    </SOAP:Envelope>


    Now that we have built our SOAP request document, we are ready to send it to the server. The request is a simple HTTP post - just like posting a web form in your internet browser. Of course, your internet browser masks all the complexity of sending a form to a server; and in the longer-term .NET will mask this process from your VB code too. But for now, we need to do the job ourselves; and I have been using Microsoft's XML HTTP Request object to give me a helping hand. (The XMLHTTPRequest is an object within the MSXML class library (MSXML.DLL), and it comes with IE5.) Assuming that strEnvelope contains the XML document described above, the request is formatted thus:

    Dim objHTTP As New MSXML.XMLHTTPRequest
    Dim strEnvelope As String

    'Set up to post to our localhost server
    objHTTP.open "post", "http://localhost/soap/soap.asp"

    'Set a standard SOAP/ XML header for the content-type
    objHTTP.setRequestHeader "Content-Type", "text/xml"

    'Set a header for the method to be called
    objHTTP.setRequestHeader "SOAPMethodName", _
    "urn:myserver/soap:TaxCalc#GetSalesTax"

    'Make the SOAP call
    objHTTP.send strEnvelope

    'Get the return value
    strReturn = objHTTP.responseBody


    Now that we have sent our request, we move to the server, to see how we set up a SOAP service to listen and respond to our calls.

    More ASP Articles
    More By ComponentSource Team


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT