ASP
  Home arrow ASP arrow Page 3 - HTTP Tunneling Revealed: Part 2/3
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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
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

HTTP Tunneling Revealed: Part 2/3
By: Adnan Masood
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2002-10-22

    Table of Contents:
  • HTTP Tunneling Revealed: Part 2/3
  • Forcing Downloads
  • Invoking a Web Service Using Only XMLHTTP
  • Implementation in .NET Using System.Net.WebClient
  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    HTTP Tunneling Revealed: Part 2/3 - Invoking a Web Service Using Only XMLHTTP


    (Page 3 of 5 )

    In this article I'm more focused on practical implementation of web services, but for those who needs details, IBM's web services architect overview is a good resource.

    XMethods, as its name suggest, is a library for methods implemented via Web Services. "This site is a "virtual laboratory" for developers , listing publicly available web services and showcasing new ways this technology can be applied".

    As they say, laughter is the best Medicine!. I have found an interesting web service for jokes by Innerpressfact (http://interpressfact.net/webservices/) that accepts a SOAP envelope with joke category ID in it and returns a random joke.

    This web service is listed on XMethods here.

    Now, down to the business! How can we implement this web service using traditional XMLHTTP? As you learned above, SOAP is a protocol to exchange information, period. It has a concrete format to exchange data over the wire. It provides the namespace, the XML schema and the required parameters to invoke the web service and read the resultant string.

    The SOAP invocation string comprises of the getjoke name space:

    <getJoke xmlns=""http://interpressfact.net/webservices/"">"

    ... the required parameter category in the DOM:

    <Category>category </Category>

    ... and last but not least, setting the headers for method invocation:
    • Setting request as the SOAP request for POST
    • Assigning a HOST for SoapServer
    • Setting the content-type as text/XML
    • Encoding the request into utf-8 format
    • Setting the SOAPAction for the invocation URI
    xmlhttp.Open "POST", "http://" & SoapServer & SoapPath, False
    xmlhttp.setRequestHeader "Man", "POST " & SoapPath & " HTTP/1.1"
    xmlhttp.setRequestHeader "Host", SoapServer
    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    xmlhttp.setRequestHeader "SOAPAction", http://interpressfact.net/webservices/getJoke

    xmlhttp.send(strSoap)


    What we receive as XML is:

    <?xml version="1.0" encoding="utf-8" ?>
    <string xmlns="http://interpressfact.net/webservices/">Q: How do you get a lawyer out of a tree? A: Cut the rope.</string>


    The XMLDOM function, xml.selectSingleNode returns the joke as the end result. The complete listing explaining the invocation is shown below:

    <%' [ Interpressfact 2002 ]

    Function getJoke(category)
    Const SoapServer = "interpressfact.net"
    Const SoapPath = "/webservices/getJoke.asmx"
    Dim xmlhttp, strSoap
    set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    'Create Soap request
    strSoap = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
    "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
    "<soap:Body>" & _
    "<getJoke xmlns=""http://interpressfact.net/webservices/"">" & _
    "<Category>" & category & "</Category>" & _
    "</getJoke>" & _
    "</soap:Body>" & _
    "</soap:Envelope>"

    'Send Soap Request
    xmlhttp.Open "POST", "http://" & SoapServer & SoapPath, False
    xmlhttp.setRequestHeader "Man", "POST " & SoapPath & " HTTP/1.1"
    xmlhttp.setRequestHeader "Host", SoapServer
    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    xmlhttp.setRequestHeader "SOAPAction", http://interpressfact.net/webservices/getJoke
    xmlhttp.send(strSoap)
    If xmlhttp.Status = 200 Then ' Response from server was success
    getJoke = xmlhttp.responseText
    Else ' Response from server failed
    getJoke = ("Temporary Error.")
    End If
    set xmlhttp = nothing
    End Function
    If request("category") <> "" then
    Dim Joke
    dim xml : set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = False
    'Load Xml From ResponseText of the getJoke function
    xml.loadxml(getJoke(request("category")))
    ' Select a Single node from ResponseText
    dim oNode : set oNode = xml.selectSingleNode("soap:Envelope/soap:Body/getJokeResponse/getJokeResult")
    'Joke variable now contains the Received Joke from the getJoke webservice
    Joke = oNode.text
    set xml = nothing
    end if
    %>
    <h1> Joke from interpressfact </h1>
    <%=joke%>


    The Interpressfact getJoke Webservice in Action

    You can invoke virtually any SOAP based web service via this mechanism, although the parameters need to be changed of course.

    More ASP Articles
    More By Adnan Masood


     

    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-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway