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...

Primitive Datatypes and Streams

The stream derived classes will work if you are reading and writing bytes of data as a block. If you need to read and write the primitive common types (Boolean, String, Int32, and so on) in and out of a stream, use the BinaryReader and the BinaryWriter classes. The Binary example shows how to use these classes. You create the appropriate stream (FileStream in the example) and pass it to the BinaryReader or BinaryWriter constructor. You can then use one of the overloaded Read or Write methods to...

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,...

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...

Unauthenticated Users

Every machine that runs .NET has a machine.config file that has the default configuration for the computer. This file is found in the directory, where v1.0.2914 would be replaced by the version of Microsoft.NET that is running on your machine. A Web or Web Service application may have a config.web file that has the configuration settings for that application. The settings for config.web affect all applications in the directory where it lives and all its subdirectories. Config.web files in the...

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...

Operating System Identity and CLR Identity

As we mentioned at the start of the chapter, .NET security sits on top of the underlying operating-system security. The identity associated with the thread by the CLR and the identity associated with the thread by the underlying operating system are not the same. The identity of the thread from the operating-system perspective is reflected by the setting of the WindowsIdentity object returned by the static Windows.Identity.GetCurrent method. The CLR identity is reflected by the value of the...

Programming Perl in the NET Environment

A very important part of the vision behind Microsoft .NET is that the platform is designed from the ground up to support multiple programming languages from many sources, and not just Microsoft languages. This book, like other books in the series, is rooted in long experience in industrial teaching. It covers the Perl language from the ground up. Although oriented toward the ActiveState Perl.NET compiler, the book also provides excellent coverage of the Perl language suitable for other versions...