Applications

The basic look and feel of the Form Designers for Windows and Web applications is the same. You drag controls from a toolbox. You set properties in a Property window. You navigate between a code view and a designer view with toolbar buttons. In the following discussion we assume you have a basic familiarity with this visual paradigm. You may find it helpful to refer back to Chapter 6. We begin by creating a simple Web page that will display information about hotels. Dropdown listboxes are...

Creating an XML Doc from a Dataset

We create a new XML document from the DataSet. Using an XPath query to get the top of the document, we set up an XmlNodeReader to read through it. We can then print out the contents of the document to the console. The XmlNodeReader class knows how to navigate through the document. XmlDataDocument xmlDataDoc new XmlDataDocument(d) XmlNode node xmlNodeReader new XmlNodeReader (node) FormatXml (xmlNodeReader) Console.WriteLine (Exception 0 , e.ToString()) if (xmlNodeReader null)...

Aspnet Configuration

In our discussion of session state we have seen a number of cases where it is desirable to be able to configure ASP.NET. There are two types of configurations Server configuration specifies default settings that apply to all ASP.NET applications. Application configuration specifies settings specific to a particular ASP.NET application. Configuration is specified in files with an XML format, which is easy to read and to modify. Server Configuration File The configuration file is machine.config....

Closing a Form

As an interesting modification to our program, let us arrange it so that whenever the user attempts to close the application, the user will be queried on whether to really close. There are several ways a window can be closed From the X at top right of the window From the system menu at the top left of the window In our application, by File Exit When a form is about to close, the Closing event is raised. You may stop the closing by setting the Cancel property in the handler for this event....

Web Service Architecture

Besides handling ASP.NET, Microsoft's Internet Information Server (IIS) can handle Web Services, since they come in as HTTP requests. These requests are encoded in the URL or as XML. IIS then creates the required object to fulfill the Web Service request. IIS then calls the object's method that is associated with the request. Any returned values are converted to XML and returned to the client, using the HTTP protocol. To illustrate how this works under Microsoft .NET, we will build a simple Web...

Wrapping a COM Component with a Pure Vtable Interface

Our example legacy COM component BankDual.dll had a dual interface IAccount2. This means that the interface could be called by both an early-binding COM client using the vtable and also by a late-binding client using IDispatch. The IDL file BankDual.idl specifies the uuid(AAAl9CDE-C0 91-47BF-8C9 6-C80A00 98 97 96), dual, helpstring(IAccount2 Interface), pointer default(unique) propget, id(1), helpstring(property Balance) HRESULT Balance( out, retval long *pVal) id(2), helpstring(method Deposit)...

Demonstration Wrapping a Legacy COM Server

The best way to get a feel for how this wrapping process works is to perform the operations yourself. The .NET client program is in the directory NetClient. The directory LegacyComServer contains the following files reg bankdual.bat Batch file to register the server unreg bankdual.bat Batch file to unregister the server BankConsole.exe Client executable file The source code for the client and server are in the directories ClientSource and ServerSource respectively. Both programs are written in...

Optimistic vs Pessimistic Locking and the Data Set

Optimism Pessimism Figure

Transactions help preserve database consistency. When you move money from your savings to your checking account to pay your phone bill, transaction processing ensures that the credit and withdrawal will both happen, or neither will happen. You will not wind up with a situation where the money goes into your checking account but is not withdrawn from the savings good for you, and bad for the bank or the reverse bad for you, but good for the bank . Nothing about that transaction prevents your...

Setup and Deployment Projects

Assemblies may be deployed as regular stand-alone binary code files i.e., DLL or EXE files , or they may be deployed using CAB, MSI, or MSM files. A CAB file is a cabinet file with the .cab file-name extension. A CAB file is used to compress and combine other files into one convenient manageable file. Although CAB files can be used for general purposes, they have traditionally been used for CD-based and Web-based installation purposes. MSI and MSM files are Microsoft Windows Installer files,...

Multiple Tables in a Data Set

Each DataSet has a collection of one or more DataTable objects. Each DataTable object represents one table. With a SelectCommand that contains a join you can place data from multiple database tables into one DataTable. If you want to update the multiple tables, you will have to specify the update commands, because all relationship of the data to the original tables is lost. The SqlDataAdapter for the HotelBroker object has the following SelectCommand property string cmd select CustomerId,...

Metadata and Reflection

The Serialization example in Chapter 2 demonstrates how metadata makes possible many of the services of the Common Language Runtime. Many of the technologies we cover in the rest of the book rely on metadata, although we will not always stop and point this out. Metadata is information about the assemblies, modules and types that constitute .NET programs. If you have ever had to create IDL to generate a type library so that your C COM objects could be called by Visual Basic, or to create proxies...

An Echo Program

The first example program for this chapter is Hello.aspx, shown as a link on the home page. The example is complete in one file and contains embedded server code. Here is the source code, which consists of HTML along with some C script code. There are also some special tags for server controls, recognized by ASP.NET. lt Page Language C gt lt SCRIPT RUNAT SERVER gt protected void cmdEcho_Click object Source, EventArgs e lblGreeting.Text Hello, txtName.Text lt FORM RUNAT SERVER gt Your name amp...

Multimodule Assemblies

An assembly can be made up of multiple modules. A module is a DLL or EXE that contains managed code plus metadata, but not necessarily a manifest. However, an assembly must have one and only one manifest. Hence an assembly can contain multiple modules, but only one of them can have a manifest that provides information on the contents of all the modules in the assembly. The module with the manifest may have just the manifest, or it can contain other code or resources. The main advantage of...

Hotel Broker Web Service

The next step in the case study is to make the Customer and Hotel components of the Hotel Broker available as a Web Service. This Web Service is found in the HotelBrokerWebService subdirectory of the case study for this chapter. This Web Service will be used both by Acme's customers to make reservations as well as by administrators for maintenance tasks associated with the Hotel Broker. The proxy classes themselves are built into a proxies assembly. Two batch files that can be used to create...

Problems with Impersonation

It would seem that we need only make sure that the user id the thread impersonates is a member of the HotelAdmin group and does not have any more privileges than are needed i.e., is not System or an administrator, with no ACL rights to any unnecessary files on the server and then everything will be just fine. Unfortunately, life is not so simple. Impersonation was designed to be used by a server to alter its rights by running a thread as another user. When the server is done impersonating a...

Static Binding

In C the normal way methods are tied to classes is through static binding. That means the object reference type is used at compile time to determine the class whose method is called. The HideEmployee program we just looked at illustrates static binding, using a simple Employee class and a derived SalaryEmployee class. Here is the test program public static void Main string args Employee emp new Employee Ellen SalaryEmployee sal new SalaryEmployee Sally, 100m emp.Show sal.Show sal emp emp sal...

Destructor Notation

The C language provides a special tilde notation SomeClass to represent the overridden Finalize method, and this special method is called a destructor. The C destructor automatically calls the base class Finalize. Thus the following C code generates code that could be expressed protected override void Finalize The second code fragment is actually not legal C syntax, and you must use the destructor notation. Although C uses the same notation and terminology for destructor as C , the two are very...