ASP
  Home arrow ASP arrow Page 4 - 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  
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

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


    HTTP Tunneling Revealed: Part 2/3 - Implementation in .NET Using System.Net.WebClient


    (Page 4 of 5 )

    Keeping backward compatibility in mind, the .NET framework has provided an enhanced set of libraries to deal with programming problems and develop solutions. Specially, by using .NET I/O and Networking libraries, what were considered much difficult tasks before can now be made simpler and intuitive.

    I'm demonstrating a simple example of this below, after a brief intro of the System.Net.WebClient class. As described in GNU (see notes), the CLI (Common Language Interface) supports URI's with the "http:", "https:", and "file:" schemes.

    The WebClient class provides the following methods for uploading data to a resource:
    • System.Net.WebClient.OpenWrite(System.String) sends a stream to the server hosting a resource.
    • System.Net.WebClient.UploadData(System.String,System.Byte[]) sends a byte array to the server hosting a resource and returns a byte array containing the response from the server, if any.
    • System.Net.WebClient.UploadFile(System.String,System.String) sends a local file to the server hosting a resource and returns a byte array containing the response from the server, if any.
    • System.Net.WebClient.UploadValues(System.String,System.Collections.Specialized.NameValueCollection) sends a NameValueCollection collection to the server hosting a resource and returns a byte array containing the response from the server, if any.
    The WebClient class also provides the following methods for downloading data from a resource:
    • System.Net.WebClient.DownloadData(System.String) downloads data from a resource and returns a byte array.
    • System.Net.WebClient.DownloadFile(System.String,System.String) downloads data from a resource to a local file.
    • System.Net.WebClient.OpenRead(System.String) returns the data from the resource as a Stream.
    In the example below, the most commonly used function of the webclient class, DownloadData, is used to demonstrate how easy it is to do what once was very difficult to perform using third part or other components:

    <%
    dim refinedstuff, pos1, pos2
    dim webC As New System.Net.WebClient()
    dim stuff as Byte()

    '//this function returns a byte array
    stuff= webC.DownloadData("http://www.census.gov/cgi-bin/ipc/popclockw")
    refinedstuff = Encoding.ASCII.GetString(stuff)
    pos1 = instr(refinedstuff, "<H1>") : pos2 = instr(refinedstuff, "</H1>")
    Response.write ("As per statistics from www.census.gov/cgi-bin/ipc/popclockw, <br>" )
    Response.write ("the world population is estimated to be " & mid (refinedstuff,pos1+4, pos2-pos1-4))s
    %>


    Demonstrating www.census.gov, world population stats

    File Uploading in ASP.NET from a Remote Server
    ASP.NET has made this task even easier than ever before. What I found most interesting is the I/O in Graphic Context System libraries, i.e. similar function handling writing streams for both HDD and web browser:

    <%
    ' instantiation of WebClient
    dim webObj AS New System.Net.WebClient()
    '// Declaring and Setting URL Variable
    dim strURL
    strURL ="http://msdn.microsoft.com/library/shared/toolbar/graphics/banners/MSDN_banner.gif"
    '// Instance of Drawing Bitmap object based on strURL
    dim graphicContext = New System.Drawing.Bitmap(webObj.OpenRead(strURL ))
    '//Setting Response types for web client
    response.contenttype="image/gif"
    '// Saving it on HDD
    graphicContext.save("C:\\Documents\\logo2.gif", graphicContext.rawformat)
    '// Writing it on web client
    graphicContext.save(response.outputstream, graphicContext.rawformat)
    ' Collecing the garbage & dereferencing
    graphicContext.dispose()
    webObj = nothing
    %>


    Showing the file written in browser as well as physically

    Web Services In .NET
    I have already explained how InterPressfact's getjoke web service works within a SOAP envelope using legacy ServerXMLHTTP, now lets move on with the development in .NET Framework.

    In the Microsoft SDK for .NET, there is a tool called "Web Services Description Language tool" (WSDL.exe). This command line executable is used to create proxy classes from WSDL. For instance, if the WSDL is located at http://www.interpressfact.net/webservices/getJoke.asmx?wsdl, then we would use the following command to create a proxy class called getJoke.cs after the name of class defined in web Service:

    wsdl http://www.interpressfact.net/webservices/getJoke.asmx?wsdl

    The Console executing the WSDL tool

    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-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek