Home arrow ASP arrow Page 4 - HTTP Tunneling Revealed: Part 2/3
ASP

HTTP Tunneling Revealed: Part 2/3


In part 2 of this article Adnan shows us how to fake a web service using XMLHTTP in ASP, how to handle HTTPS authentication via ServerXMLHTTP and more.

Author Info:
By: Adnan Masood
Rating: 5 stars5 stars5 stars5 stars5 stars / 27
October 22, 2002
TABLE OF CONTENTS:
  1. · HTTP Tunneling Revealed: Part 2/3
  2. · Forcing Downloads
  3. · Invoking a Web Service Using Only XMLHTTP
  4. · Implementation in .NET Using System.Net.WebClient
  5. · Conclusion

print this article
SEARCH DEVARTICLES

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
blog comments powered by Disqus
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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials