NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

A Client using ASP+

One of the most important features of NGWS is the ability to execute the same code in IIS's Active Server Pages (ASP+) as was used in our stand-alone client applications. Of course, there are a few differences: The ASP+ page generally produces HTML in response to an HTTP request, and the page itself is compiled dynamically, unlike what was done for the previous examples. Each ASP+ page is individually parsed and the syntax is checked. Finally, a NGWS runtime class is produced, which is compiled and then invoked. ASP+ caches the compiled object, so subsequent requests don't go through the parse/compile step and thus execute much faster.

Most existing ASP pages use JScript or VBScript: We have chosen to show the page using C#, which would be a natural evolution for JScript code (VBScript code would upgrade quite naturally to VB):

Listing 11. Client in ASP+ (ClientASP+.aspx)

<%@ Page Language="C#" Description="ASP+ Component Test" %>
<%@ Import Namespace="CompCS"%>
<%@ Import Namespace="CompVC"%>
<%@ Import Namespace="CompVB"%>

<html>
<script language="C#" runat=server>
void Page_Load(Object sender, EventArgs EvArgs) {
   String Out = "";
   Int32 Count = 0;

   // Iterate over component's strings and concatenate 
   Out = Out + "Strings from C# StringComponent<br>";
   CompCS.StringComponent myCSStringComp = new 
   CompCS.StringComponent();
   for (int index = 0; index < myCSStringComp.Count; index++) {
      Out = Out + myCSStringComp.GetString(index) + "<br>";
   }
   Out = Out + "<br>";

   // Iterate over component's strings and concatenate 
   Out = Out + "Strings from VC StringComponent<br>";
   CompVC.StringComponent myVCStringComp = new 
   CompVC.StringComponent();
   for (int index = 0; index < myVCStringComp.Count; index++) {
      Out = Out + myVCStringComp.GetString(index) + "<br>";
   }
   Out = Out + "<br>";

   // Iterate over component's strings and concatenate 
   Out = Out + "Strings from VB StringComponent<br>";
   CompVB.StringComponent myVBStringComp = new 
   CompVB.StringComponent();
   for (int index = 0; index < myVBStringComp.Count; index++) {
      Out = Out + myVBStringComp.GetString(index) + "<br>";
   }

   Message.InnerHtml = Out;
}
</script>
<body>
   <span id="Message" runat=server/>
</body>
</html>

This is essentially the same code as for the stand-alone client examples, except that we are building a string (named out) that we are then assigning to a property of an HTML server control. We could also have used the familiar Response.Write to write the string directly into the HTML output stream.

The page specifies C# as a language:

<%@ Page Language="C#" Description="ASP+ Component Test"

but we could just as easily have used VB or even JScript.

Importing libraries in ASP+ is also a little different:

<%@ Import Namespace="CompVB"%>
<%@ Import Namespace="CompCS"%>
<%@ Import Namespace="CompVC"%>

In these examples, delimited by "<%…%>" to indicate script code, we are specifying both the namespace and the physical assembly. As mentioned above, the assemblies must be located "\Bin" subdirectory of the application's starting point.

Another subtlety of this page is this line:

<script language="C#" runat="server">

This tells the server to execute the code on the server rather than sending the code text back to the client as part of the HTML stream.

ASP+ Web Forms provides special recognition of six methods named:

These methods are automatically connected to event handlers for the standard page events. The most commonly used event is Load, which contains most of the code for our sample program:

void Page_Load(Object sender, EventArgs EvArgs) {…}

The rest of the code is pretty straightforward: We're just concatenating together a longer string out that we then add to the HTML with this statement:

StringOut.innerHTML = Out

Testing this page requires a few steps. First, it's necessary for the test machine to have the following installed:

Installing the PDC Tech Preview of the NGWS SDK on a machine that already has IIS installed will enable that machine to run ASP+ (if you install IIS after installing the SDK, you should reinstall the SDK). Next, you must configure a virtual directory (using Internet Services Manager) that points to the directory where ClientASP.aspx is located. To create a virtual directory using the Internet Information Services snap-in:

If you are using NTFS, you can also create a virtual directory by right-clicking a directory in Windows Explorer, clicking Sharing, and then selecting the Web Sharing property sheet. For more information, see the topic "Creating Virtual Directories" in the IIS documentation, which is located at http://localhost/iisHelp/ on the machine on which IIS is installed.

Third, the compiled component dlls should be located in "\Bin" subdirectory under the starting point for the application virtual directory.

Assuming everything is configured correctly, executing the file with, for instance, the following URL:

http://localhost/Com20Dev/ClientASP+.aspx

should result in an instance of Internet Explorer with a display similar to this: