Dynamic
Content On Edge Cache Server
(Using Microsoft
.NET)
Index
1. Introduction
2. Caching
5. Code examples explaining DOTNET Web Service taken from the Microsoft tutorial
7. Task
8. Code Related to the project
10. Related Links
As the number of Internet users is growing very fast, the problems of limited bandwidth and consequent network congestion and overloading of Web servers is becoming more pronounced. Web caching is one popular mechanism to reduce access latency and bandwidth congestion. An increasing proportion of web content is dynamic. This project is based on the Dynamic content on the cache server using DOTNET web services. In this document I have discussed about what is Caching and Dynamic Caching and DOTNET web services and what does web services provide to the users and how I solved my project using this service. I have displayed some of the examples using DOTNET web services provided by the Microsoft and some code related to this project.
Usually when clients request a Web page it is saved to disk. If it is required again, the disk copy is served. This technique is used in all modern browsers such as Internet Explorer and Netscape Navigator. In proxy cache web server (site between the web browser/client and the server) users request pages from a local proxy server instead of direct from the source. This proxy acts as an intermediary by fetching document and then passing them to browser. Additionally, it can save copies of the documents to form a collection ('cache') of documents that are available immediately when they are requested; it is referred to as a web proxy server. Subsequent requests from other users of the cache get the saved copy, which is much faster and does not consume Internet bandwidth over the often-congested international network links.
Figure –1 Describing caching
In Dynamic Caching the content on the web server change for each individual user request or must be updated frequently (e.g., stock quotes, auction bidding pages, advertising banners, answer queries, news information, local time, etc). The dynamic page is retrieved from the original server and stored in a cache, when the user retrieves it from the cache some time later, they may not see the page as it was meant to be seen, either because the information has been updated, or other variation determined by server-side processing like data base change. As well dynamic documents constitute an increasing percentage of contents on the Web, and caching dynamic documents becomes an increasingly important issue that affects the scalability of the Web.
To solve this problem I am using the DOTNET web services provided by the Microsoft.
4. ABOUT DOTNET WEB SERVICE
The Web
services from the DOTNET provide us a simple, flexible, standards-based model for
required applications together over the Internet that takes advantage of
existing infrastructure and applications. To explain .NET to
non-technical people, it is like if one knows English and other does not there
cannot be any conversation. In IT, these modules are called Procedures. When
one Procedure asks another Procedure something, it is said to "call"
it. These are called Remote Procedure Calls (RPCs). Until .NET came out, it
mattered very much which language software was written in, or on what Operating
System it was meant to run under. Windows, Macintosh, Unix, all talked
different languages. It does not have a fixed language that you need to code
for it. You can code in C, C++, Java, COBOL, VB, or any language of your
choice. .NET Framework is the base that allows all those languages to be
compiled to what is known as IL-Code (Intermediate-Language code). IL code
allows wide portability across platforms that support Common Language Runtime
(CLR). CLR is basically the .NET Framework itself. CLR is basically the .NET Framework itself, which include base
classes and other components needed to create applications of such sorts.
Another feature implemented into the CLR is the garbage collector. It
automatically collects and frees memory used by obsolete threads, processes and
database connections.
Figure – 2 DOTNET Architecture
Figure above shows the Microsoft .NET Framework architecture. Built on top of operating system services is a common language runtime that manages the needs of running code written in any modern programming language. The .NET Framework includes a set of class libraries that developers can use from any programming language. Above that sit various application programming models that provide higher-level components and services targeted specifically at developing Web sites and Web Services.
Web
Service Features
Web services provide us with application integration i.e. taking a group of applications and turning them into user-friendly Web applications, even applications running on different operating systems, were created with different programming languages, and were built with different object models. Developers can reuse with no worrying about how to implement the service. Web services provide well-defined interfaces (called contracts) that describe the services they represent. Developers can assemble applications by using a combination of remote services, local services, and custom code.
Example: A company might assemble an online store that uses the Microsoft Passport service to authenticate users, a third-party personalization service to adapt Web pages to each user's preferences, a credit-card processing service, an in-house catalog service that connects to the company's internal inventory management applications, and custom code to individualize the interface and make it unique. Web services do not use protocols that are specific to certain object models, such as the Distributed Component Object Model (DCOM). DCOM requires specific homogeneous infrastructures on the computers that run the client and the server.
Web services communicate by using standard Web protocols and data formats, such as Hypertext Transfer Protocol (HTTP), Extensible Markup Language (XML), and Extensible Markup Language Protocol (XMLP). Web service can be used internally by a single application, or it can be used externally by many applications that access it through the Internet. Because it is accessible through a standard interface, a Web service allows disparate systems to work together. The Web services model is independent of languages, platforms, and object models.
The Web service model is supported by ASP.NET, grown from Active Server Pages technology. Each time a service request is received, a new object is created. The request for the method call, and the object is destroyed after the method call is returned.
Figure –3 this figure illustrate how Web services are used between a client and the Web server (taken from the Microsoft training Site)
The Web services execution model involves two entities, the client and the service provider. Client is a Web browser that views the results of calling a Web service. Each component has a specific role in the execution model.
Web Service Models
Web services offer "services" over the "web". The
communication between your ASP.NET pages and web service is via HTTP protocol
using SOAP standards (Simple Object Access Protocol). Usually the ASP.NET page
requests a service from a Web Service component, the request is converted into
SOAP format (which is in XML). The web service processes ther request and sends
back the result again in an XML format over SOAP.
Points to note about web services:
§
The ASP.NET page
requests a service from a Web Service component.
§
This request is
converted into SOAP format (which is in XML).
§
The web service
processes the request and sends back the result again in an XML format over
SOAP.
5. CODE EXAMPLES EXPLAINING DOTNET WEB SERVICE TAKEN FROM
THE MICROSOFT TUTORIAL
GreetingService.asmx
ExampleService.asmx
Stock.asmx
GetStocks.aspx
webcontrole.aspx
httpcontrol.aspx
A
simple web service called Greeting Service; this web service provides various greeting
messages. Pass an integer to indicate the type of message you want e.g.
Birthday Greetings, New Year Greetings etc. Following are the steps involved in
creating a web service:
§
GreetingService.asmx
file containing source code for the service
§
Convert
GreetingService.asmx file into VB or C# source code file
§
Compile VB or C#
source code formed
§
Deploy the
resulting DLL to the applications bin folder
<%@ webservice language="VB"
class="greetings"%>
imports system.web.services
public Class greetings
<WebMethod()> public function getMsg(id as integer)as
string
select
case id
case 101
getMsg="Happy Birthday"
case 102
getMsg="Happy New Year"
case else
getMsg="Seasons
Greetings"
end select
end function
end class
Description
of the code above
§
Webservice code
is stored as .asmx extension ( GreetingService.asmx ). In the directory
C:/Inetpub/wwwroot
§
The first line
in the code <%@ webservice language="VB"
class="greetings"%> Explains the webservice directive
indicates that this is a web service. Language attribute specifies the language
used to write the web service. We have used VB in our example. The class
attribute specifies the class name that constitutes the web service. One
.asmx file can have multiple class files (some of which may be supporting
classes). Out of available classes the class specified in the class
attribute is used for creating the web service.
§
<WebMethod()> Public function getMsg(id as
integer) as string. This line marks getMsg() method as the "web
callable" method. This method returns the greeting message based on id we
pass
Convert .asmx file into VB or C# source code
file
Web
service source code for the GreetingService.asmx, we need to convert it into VB
source code. To do this conversion ASP.NET comes with a utility called
WebServiceUtil.exe. This utility is used for other purposes as well we now here
us to generate VB source code. Type in the following command at the DOS prompt:
WebServiceUtil /c:proxy /pa:http://localhost/mywebapp/GreetingService.asmx?sdl
/l:VB /n:GreetingService
Explanation:
·
/c:proxy represents that we want to create proxy for
the client
·
/pa:http://localhost/mywebapp/GreetingService.asmx?sdl We need to supply the SDL of the web service.
This can be achieved by appending SDL to the path of our .asmx file. You can
even invoke this URL in browser and view the resulting XML code.
·
/l:VB Specifies that the resulting code should be
generated in VB
·
/n:GreetingService
Indicates that name for the resulting namespace should be GreetingService
After executing above command we get a file greetings.vb. This file below is generated by the system:
'--------------------------------------------------------
' <autogenerated>
' This class was generated by a tool.
' Runtime Version: 2000.14.1812.10
'
' Changes to this file may cause incorrect
' behavior and will be lost if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------
Imports System.Xml.Serialization
Imports System.Web.Services.Protocols
Imports System.Web.Services
Namespace GreetingService
Public Class Greetings
Inherits System.Web.Services.Protocols.SoapClientProtocol
Public Sub New()
MyBase.New
Me.Path = "http://localhost/BAJSamples/ASPPlus/WebServices/GreetingService.asmx"
End Sub
<System.Web.Services.Protocols.SoapMethodAttribute("http://tempuri.org/getMsg", RequestElementName:="getMsg", ResponseElementName:="getMsgResult")> Public Function GetMsg(ByVal id As Integer) As String
Dim results As Object() = Me.Invoke("GetMsg", New Object() {id})
return CType(results(0),String)
End Function
Public Function BeginGetMsg(ByVal id As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
return Me.BeginInvoke("GetMsg", New Object() {id}, callback, asyncState)
End Function
Public Function EndGetMsg(ByVal asyncResult As System.IAsyncResult) As String
Dim results As Object() = Me.EndInvoke(asyncResult)
return CType(results(0),String)
End Function
End Class
End Namespace
Compile VB or C# source code
On compiling the VB source code we get the final
DLL.
Type in following command:
vbc
/out:GreetingService.dll
/t:library
/r:System.Xml.Serialization.dll
/r:System.Web.Services.dll
Greetings.vb
pause
At this point I have the
GreetingService.DLL. To use the DLL
created, I have to copy it in the \bin folder (not found create one) of web application.
To test the web
service
To test the web service
I created use it in an ASP.NET page. Use following .aspx code
<%@
language="VB"%>
<script
runat=server>
public
sub showmsg(s as Object,e as EventArgs)
dim c as GreetingService.Greetings
c=new GreetingService.Greetings()
label1.text=c.getMsg(101)
end
sub
</script>
<form
runat=server>
<asp:label
id=label1 runat=server text="no msg set yet"/>
<asp:button
id=btn1 runat=server onclick="showmsg" text="Click" />
</form>
Here
I created an instance of the web service component just like any other object.
The DLL file is already in the bin folder, our service is already available to
the ASP.NET page.
Calling
a Web Service from a Browser
Creating a web service
To explain the Web service model:
§ I have Created the .asmx file that includes the namespace, classes, properties, and methods.
§ Declares methods as Web methods that can be accessed over the Internet.
Example: URL: http://wind.uccs.edu/ayeddula/ExampleService.asmx
<%@ WebService Language="VB"
Class="ExampleService" %>
Imports System.Web.Services
Imports System
Class ExampleService
<WebMethod()> Public
Function HelloWorld() As String
HelloWorld = "Hello World"
End Function
<WebMethod()> Public
Function Price() As String
Price = "The item costs $10"
End function
<WebMethod()> public
Function Add(int1 As Integer, int2 As Integer) As Integer
return(int1 + int2)
End Function
<WebMethod()> public
Function Subtract(int1 As Integer, int2 As Integer) As Integer
return(int1 - int2)
End Function
<WebMethod()> public
Function Multiply(int1 As Integer, int2 As Integer) As Integer
return(int1 * int2)
End Function
<WebMethod()> public
Function Divide(int1 As Integer, int2 As Integer) As Integer
return(int1 / int2)
End Function
End Class
In the example above when you call the Web service from a browser (here we access the description page) this page lists the methods that are included in the Web service. The protocol that is used in this case is HTTP, and the data is returned as XML.
Creating
a Web Service Using Visual Studio.NET
Stock.asmx URL: http://wind.uccs.edu/ayeddula/Stocks.asmx
<WebMethod()> Public Function GetRating(ByVal Ticker As String) As String
If Ticker = "ACME" Then
Return "Buy"
Else
Return "Sell"
End If
End Function
Calling
a Web Service Using Visual Studio.NET
GetStocks.aspx URL: http://wind.uccs.edu/ayeddula/GetStocks.aspx
Sub Button1_Click(ByVal s As Object, ByVal e As EventArgs)
Dim service As New
GetStocks.localhost.Service1()
Label1.Text = service.GetRating(TextBox1.Text)
End Sub
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="GetStocks.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<asp:textbox id="TextBox1" runat="server" />
<asp:button id="Button1" Text="Advise (Buy or Sell)" onClick="Button1_Click" runat="server" />
<asp:Label id="Label1" runat="server" />
</form>
</body>
</HTML>
Creating a Web Control (event e.g onclick)
Two server controls
1.
Web
controls:
provide a new syntax but have consistent usage. All web controls have a
collection called Attributes. This collection is designed for down level
browsers and you can put javascript event handlers in it.
Example: URL http://wind.uccs.edu/~ayeddula/dotnet/webcontrol.aspx
<form id="Form1"
method="post" runat="server">
<asp:Button id="Button1" runat="server"
Text="Button">
</asp:Button>
</form>
Private Sub Page_Load (ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add("onclick",
"javascript:alert('hello world')")
End Sub
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Response.Write("Click fired...")
End Sub
2. HTML controls: Places where we use both events (client side as well as server side) you can use HTML controls. Usual event names of HTML controls OnServerxxxx, where xxxx stands for the event e.g. OnServerClick here in this example below
Example: URL: http://wind.uccs.edu/~ayeddula/dotnet/httpcontrol.aspx
<form id="Form1" method="post" runat="server">
<INPUT id="Button1" type="button" value="Button"
name="Button1" runat="server"
onclick="alert('hello world');">
</form>
Private Sub Button1_ServerClick (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
Response.Write("ServerClick fired...")
End Sub
First we set a proxy server in the browser (in the browser go to Tools + Internet options + connections + LAN settings + use proxy server to set the proxy). When a URL for a dynamic page is entered into a browser, the client establishes a stream connection with the proxy server (set it in tools menu as I mentioned above) and sends a HTTP request. The proxy server strips the HTTP information and maintains a connection to the application server that executes a script to build the page. This script can be actions such as queries to local and/or remote database systems to retrieve content. The proxy checks the page for the dynamic content and sends the request back to the application server to get the dynamic information and saves a cache copy in the proxy server and then the page is delivered back to the browser.
Conversion of the XML to HTML
In the asmx web page the data is returned as XML to the web browser there should be some way to convert this XML to
HTML This is made possible by the use of XSLT, a language used to transform an
XML document into some other specified format (e.g., HTML, text). However this
XML to HTML transformation process increases the load on the server, because it
involves parsing and other string-processing operations.
7. TASK
As Web pages become more database-driven and dynamic, it is important that Web browsers display the most up-to-date information available from Original site. One solution is servers to supply cache applets to be attached with the request documents, and requires proxies to invoke cache applets upon cache hits to furnish the necessary processing without contacting the server.
Code solution
- First build some Dynamic web pages on the Server side, which are served on request by the client.
- Client (or Web Browser) sends request i.e. URL to be fetched. On the Browser we are setting proxy in the Internet Options, which acts as our Proxy Server.
- The proxy (or cache) server will receive a request for a webpage as a URI (Uniform Resource Identifer) from client (web browser). The proxy server will check its cache for the page
o If the page is not in the cache, it will retrieve the page from the original server and place it in the cache. The page will then be transmitted from the cache to the client (web browser).
o Else if page found in the proxy
§ If the files has. aspx or. asmx extension look in the content for the VB Script. Retrieve only dynamic content from original server and transmits to the client(web browser).
Dynamic change in date and time on the
client side
To View Code (click
view menu bar and source)
o
Code is written
in java script.
o
This code
supports both the IE and Netscape.
o
The dynamically
change in date and time is on the client side.
o
I have also
shown code written on the server side using DOTNET web service in VB script.
Dynamic change in date and time using DOTNET on the server side URL:http://wind.uccs.edu/ayeddula/dotnet/timeaspx.aspx
<%@ Page Language="VB" %>
<HTML>
<HEAD>
<META HTTP-EQUIV="REFRESH" CONTENT="1">
<script language="VB" id="Script1" runat="server">
Sub Page_Load()
dim dtNow as DateTime
dtNow = DateTime.Now
lblNow.Text = dtNow.ToString
End Sub
</script>
</HEAD>
<body id="Body1" runat="server">
<p>
Date And Time using .NET.
</p>
<asp:label id="lblNow" runat="server"></asp:label>
</body>
</HTML>
Dynamic date and time using DOTNET on the server side : URL:http://wind.uccs.edu/ayeddula/dotnet/timeasmx.asmx
<%@ WebService Language="VB" Class="timeasmx" %>
Imports System.Web.Services
Imports System
Class timeasmx
<WebMethod()> Public Function GetTime() As String
Dim dtNow As DateTime
dtNow = DateTime.Now
GetTime = dtNow.ToString
End Function
End Class
Active server page (ASP) with Database access :
URL : http://wind.uccs.edu/ayeddula/asp/search.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<form method="GET" action="response.asp">
Search LastName: <input NAME="LastName" SIZE="30">
<input type="submit" value="Submit">
<p> ShowAll: <input NAME="All" SIZE="30">
<input type="submit" value="ShowAll">
</form>
</body>
</html>
URL: http://wind.uccs.edu/ayeddula/asp/Response.asp
<%Language=VBScript
' On Error Resume Next</p>
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
Conn.Open "cs401signup"
key = Request.QueryString("LastName")
key1 = Request.QueryString("All")
Response.Write (key)
Response.Write (key1)
if (key1 <> "All") then
sql="select * from signup where LastName='" & key & "'"
' Response.Write (key)
Else
sql="select * from signup"
' Response.Write (key1)
end if
RS.open sql,conn
' where LastName='" & key & "'"
%>
<html>
<head>
<title> sign up response.asp File </title>
</head>
<body>
<center>
<%
if RS.RECORDCOUNT = 0 THEN
%>
<font size="5"><b>No Match Result</b></font>
<%End If%>
TEST PROGRAM FOR THE ASP USING MICROSOFT ACCESS
<p>
<p>
<table border=3 width=410>
<%Do While Not RS.EOF%>
<tr>
<td width=170 valign=top>
<FONT SIZE=4 COLOR=Green><%=RS("LastName")%> </font>
</td>
<td width=170 valign=top>
<FONT SIZE=4 COLOR=Green><%=RS("FirstName")%> </font>
</td>
<td width=270 valign=top>
<FONT SIZE=4 COLOR=Green><%=RS("Address")%> </font>
</td>
<td width=430 valign=top>
<FONT SIZE=4 COLOR=Green><%=RS("PhoneNumber")%> </font>
</td>
</tr>
<%
RS.MoveNext
Loop
%>
<%
rs.close
set rs=nothing
set conn=nothing
%>
</table>
<a href="http://localhost/cs401www/search.htm">
</body>
</html>
Simple Client.java
/ Server.java Code
/* First we have
to start the server on the port number 8080, then client connects to the server
with the same port number 8080 and client sends the message to the server and
server replies back to the client in the upper case to show the difference */
//
file name : Client.java
import
java.io.*;
import
java.net.*;
public
class Client {
public
static void main(String[] args) throws Exception {
if(args.length!=1)
{
System.err.println("Error
Enter: java Client 128.198.192.202") ;
System.exit(1) ;
}
String
destName=args[0] ;
Socket clientSocket=new
Socket(destName,8080) ;
DataOutputStream
outToServer=new DataOutputStream(clientSocket.getOutputStream());
BufferedReader
inFromServer=new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
BufferedReader bufferedKbd = new
BufferedReader (new FileReader (FileDescriptor.in));
System.out.print("Enter Message
to Server -> ");
System.out.flush ();
String message =
bufferedKbd.readLine ();
outToServer.writeBytes(message
+ "\n") ;
String answer=inFromServer.readLine()
;
System.out.println("Received
from Server: "+answer) ;
clientSocket.close() ;
}//end
main
}//end
class client
// file name : Server.java
import java.io.*;
import java.net.*;
class Server {
public static void main(String[] args) throws Exception {
ServerSocket welcomeSocket=new ServerSocket(8080) ;
System.out.println("Server Started at Port Number "+ 8080) ;
while(true) {
try {
Socket connSocket = welcomeSocket.accept() ;
BufferedReader inFromClient=new BufferedReader(new InputStreamReader(connSocket.getInputStream())) ;
DataOutputStream outToClient=new DataOutputStream(connSocket.getOutputStream());
String message=inFromClient.readLine();
System.out.println("Message received from Client: "+message) ;
System.out.println("\n-------test-----------------------------\n" );
String answer=message.toUpperCase()+'\n' ;
outToClient.writeBytes(answer);
} catch(IOException e){}
}// end while
} // end main
}// end class server
Proxy Java
Code
URL: http://cs.uccs.edu/~ayeddula/project_files/ProxyServer.java
Original
Server Java Code
URL: http://cs.uccs.edu/~ayeddula/project_files/OriginalServer.java
Text
Reader Java Code
URL: http://cs.uccs.edu/~ayeddula/project_files/TextReader.java
9. CONCLUSION AND FUTURE WORK
This project
proposes using Microsoft’s latest DOTNET Web services to support caching of
dynamic documents on the Web. Also included in this document I have listed web
services provided by Microsoft, i.e. creating a web service and calling a web
service, creating and calling a Web Service using Visual Studio.NET and calling
a Web Service using a Proxy. The key factor is the solution for Web caching.
The Project till now includes creating dynamic pages (using .NET to display the
time, asp pages with data base access, study of JDBC) and accessing via proxy.
I have written code for proxy in Java to cache the user requests and display
the return documents in html format. The .asmx web page returns data in XML
format to the web browser and at this point the task is to convert this XML to
HTML only. Future work includes getting the HTTP information from the browser
and establishing connection to the original server to get the dynamic
information.
10. RELATED LINKS
1. Class Website: CS522
2. Microsoft Web Service Article: http://www.microsoft.com/mobile/developer/technicalarticles/msnet.asp
3. Related programs during research work in DOTNET: http://www.cs.uccs.edu/~chow/pub/DotNet
4. Active Cache: Caching Dynamic Contents on the Web Active Cache
5. Courses for DOTNET http://www.microsoft.com/traincert/training/developer/dotnet.asp
6. DOTNET discussions http://discuss.develop.com/archives/wa.exe?A0=dotnet&D=0&H=0&O=D&T=1
------------------------------------------------------------------------END PROJECT---------------------------------------------------------------------------