- •About the Authors
- •Contents at a Glance
- •Contents
- •Introduction
- •Goal of the Book
- •How to Use this Book
- •Introduction to the .NET Framework
- •Common Language Runtime (CLR)
- •Class Library
- •Assembly
- •Versioning
- •Exceptions
- •Threads
- •Delegates
- •Summary
- •Introduction to C#
- •Variables
- •Initializing Variables
- •Variable Modifiers
- •Variable Data Types
- •Types of Variables
- •Variable Scope
- •Types of Data Type Casting
- •Arrays
- •Strings
- •Initializing Strings
- •Working with Strings
- •Statements and Expressions
- •Types of Statements
- •Expressions
- •Summary
- •Classes
- •Declaring Classes
- •Inheritance
- •Constructors
- •Destructors
- •Methods
- •Declaring a Method
- •Calling a Method
- •Passing Parameters to Methods
- •Method Modifiers
- •Overloading a Method
- •Namespaces
- •Declaring Namespaces
- •Aliases
- •Structs
- •Enumerations
- •Interfaces
- •Writing, Compiling, and Executing
- •Writing a C# Program
- •Compiling a C# Program
- •Executing a C# Program
- •Summary
- •Arrays
- •Single-Dimensional Arrays
- •Multidimensional Arrays
- •Methods in Arrays
- •Collections
- •Creating Collections
- •Working with Collections
- •Indexers
- •Boxing and Unboxing
- •Preprocessor Directives
- •Summary
- •Attributes
- •Declaring Attributes
- •Attribute Class
- •Attribute Parameters
- •Default Attributes
- •Properties
- •Declaring Properties
- •Accessors
- •Types of Properties
- •Summary
- •Introduction to Threads
- •Creating Threads
- •Aborting Threads
- •Joining Threads
- •Suspending Threads
- •Making Threads Sleep
- •Thread States
- •Thread Priorities
- •Synchronization
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Primary and Foreign Keys
- •Referential Integrity
- •Normalization
- •Designing a Database
- •Low-Level Design
- •Construction
- •Integration and Testing
- •User Acceptance Testing
- •Implementation
- •Operations and Maintenance
- •Summary
- •Creating a New Project
- •Console Application
- •Windows Applications
- •Creating a Windows Application for the Customer Maintenance Project
- •Creating an Interface for Form1
- •Creating an Interface for WorkerForm
- •Creating an Interface for CustomerForm
- •Creating an Interface for ReportsForm
- •Creating an Interface for JobDetailsForm
- •Summary
- •Performing Validations
- •Identifying the Validation Mechanism
- •Using the ErrorProvider Control
- •Handling Exceptions
- •Using the try and catch Statements
- •Using the Debug and Trace Classes
- •Using the Debugging Features of Visual Studio .NET
- •Using the Task List
- •Summary
- •Creating Form1
- •Connecting WorkerForm to the Workers Table
- •Connecting CustomerForm to the tblCustomer Table
- •Connecting the JobDetails Form
- •to the tblJobDetails Table
- •Summary
- •Introduction to the Crystal Reports Designer Tool
- •Creating the Reports Form
- •Creating Crystal Reports
- •Creating the Windows Forms Viewer Control
- •Creating the Monthly Worker Report
- •Summary
- •Introduction to Deploying a Windows Application
- •Deployment Projects Available in Visual Studio .NET
- •Deployment Project Editors
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Populating the TreeView Control
- •Displaying Employee Codes in the TreeView Control
- •Event Handling
- •Displaying Employee Details in the ListView Control
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Adding the Programming Logic to the Application
- •Adding Code to the Form Load() Method
- •Adding Code to the OK Button
- •Adding Code to the Exit Button
- •Summary
- •The Created Event
- •Adding Code to the Created Event
- •Overview of XML
- •The XmlReader Class
- •The XmlWriter Class
- •Displaying Data in an XML Document
- •Displaying an Error Message in the Event Log
- •Displaying Event Entries from Event Viewer
- •Displaying Data from the Summary.xml Document in a Message Box
- •Summary
- •Airline Profile
- •Role of a Business Manager
- •Role of a Network Administrator
- •Role of a Line-of-Business Executive
- •Project Requirements
- •Creation and Deletion of User Accounts
- •Addition of Flight Details
- •Reservations
- •Cancellations
- •Query of Status
- •Confirmation of Tickets
- •Creation of Reports
- •Launch of Frequent Flier Programs
- •Summarizing the Tasks
- •Project Design
- •Database Design
- •Web Forms Design
- •Enabling Security with the Directory Structure
- •Summary
- •Getting Started with ASP.NET
- •Prerequisites for ASP.NET Applications
- •New Features in ASP.NET
- •Types of ASP.NET Applications
- •Exploring ASP.NET Web Applications
- •Introducing Web Forms
- •Web Form Server Controls
- •Configuring ASP.NET Applications
- •Configuring Security for ASP.NET Applications
- •Deploying ASP.NET Applications
- •Creating a Sample ASP.NET Application
- •Creating a New Project
- •Adding Controls to the Project
- •Coding the Application
- •Summary
- •Creating the Database Schema
- •Creating Database Tables
- •Managing Primary Keys and Relationships
- •Viewing the Database Schema
- •Designing Application Forms
- •Standardizing the Interface of the Application
- •Common Forms in the Application
- •Forms for Network Administrators
- •Forms for Business Managers
- •Forms for Line-of-Business Executives
- •Summary
- •The Default.aspx Form
- •The Logoff.aspx Form
- •The ManageUsers.aspx Form
- •The ManageDatabases.aspx Form
- •The ChangePassword.aspx Form
- •Restricting Access to Web Forms
- •The AddFl.aspx Form
- •The RequestID.aspx Form
- •The Reports.aspx Form
- •The FreqFl.aspx Form
- •Coding the Forms for LOB Executives
- •The CreateRes.aspx Form
- •The CancelRes.aspx Form
- •The QueryStat.aspx Form
- •The ConfirmRes.aspx Form
- •Summary
- •Designing the Form
- •The View New Flights Option
- •The View Ticket Status Option
- •The View Flight Status Option
- •The Confirm Reservation Option
- •Testing the Application
- •Summary
- •Locating Errors in Programs
- •Watch Window
- •Locals Window
- •Call Stack Window
- •Autos Window
- •Command Window
- •Testing the Application
- •Summary
- •Managing the Databases
- •Backing Up the SkyShark Airlines Databases
- •Exporting Data from Databases
- •Examining Database Logs
- •Scheduling Database Maintenance Tasks
- •Managing Internet Information Server
- •Configuring IIS Error Pages
- •Managing Web Server Log Files
- •Summary
- •Authentication Mechanisms
- •Securing a Web Site with IIS and ASP.NET
- •Configuring IIS Authentication
- •Configuring Authentication in ASP.NET
- •Securing SQL Server
- •Summary
- •Deployment Scenarios
- •Deployment Editors
- •Creating a Deployment Project
- •Adding the Output of SkySharkDeploy to the Deployment Project
- •Deploying the Project to a Web Server on Another Computer
- •Summary
- •Organization Profile
- •Project Requirements
- •Querying for Information about All Books
- •Querying for Information about Books Based on Criteria
- •Ordering a Book on the Web Site
- •Project Design
- •Database Design
- •Database Schema
- •Web Forms Design
- •Flowcharts for the Web Forms Modules
- •Summary
- •Introduction to ASP.NET Web Services
- •Web Service Architecture
- •Working of a Web Service
- •Technologies Used in Web Services
- •XML in a Web Service
- •WSDL in a Web Service
- •SOAP in a Web Service
- •UDDI in a Web Service
- •Web Services in the .NET Framework
- •The Default Code Generated for a Web Service
- •Testing the SampleWebService Web Service
- •Summary
- •Creating the SearchAll() Web Method
- •Creating the SrchISBN() Web Method
- •Creating the AcceptDetails() Web Method
- •Creating the GenerateOrder() Web Method
- •Testing the Web Service
- •Securing a Web Service
- •Summary
- •Creating the Web Forms for the Bookers Paradise Web Site
- •Adding Code to the Web Forms
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Overview of Mobile Applications
- •The Microsoft Mobile Internet Toolkit
- •Overview of WAP
- •The WAP Architecture
- •Overview of WML
- •The Mobile Web Form
- •The Design of the MobileTimeRetriever Application
- •Creating the Interface for the Mobile Web Forms
- •Adding Code to the MobileTimeRetriever Application
- •Summary
- •Creating the Forms Required for the MobileCallStatus Application
- •Creating the frmLogon Form
- •Creating the frmSelectOption Form
- •Creating the frmPending Form
- •Creating the frmUnattended Form
- •Adding Code to the Submit Button in the frmLogon Form
- •Adding Code to the Query Button in the frmSelectOption Form
- •Adding Code to the Mark checked as complete Button in the frmPending Form
- •Adding Code to the Back Button in the frmPending Form
- •Adding Code to the Accept checked call(s) Button in the frmUnattended Form
- •Adding Code to the Back Button in the frmUnattended Form
- •Summary
- •What Is COM?
- •Windows DNA
- •Microsoft Transaction Server (MTS)
- •.NET Interoperability
- •COM Interoperability
- •Messaging
- •Benefits of Message Queues
- •Limitations
- •Key Messaging Terms
- •Summary
- •Pointers
- •Declaring Pointers
- •Types of Code
- •Implementing Pointers
- •Using Pointers with Managed Code
- •Working with Pointers
- •Compiling Unsafe Code
- •Summary
- •Introduction to the Languages of Visual Studio .NET
- •Visual C# .NET
- •Visual Basic .NET
- •Visual C++ .NET
- •Overview of Visual Basic .NET
- •Abstraction
- •Encapsulation
- •Inheritance
- •Polymorphism
- •Components of Visual Basic .NET
- •Variables
- •Constants
- •Operators
- •Arrays
- •Collections
- •Procedures
- •Arguments
- •Functions
- •Adding Code to the Submit Button
- •Adding Code to the Exit Button
- •Summary
- •Introduction to Visual Studio .NET IDE
- •Menu Bar
- •Toolbars
- •Visual Studio .NET IDE Windows
- •Toolbox
- •The Task List Window
- •Managing Windows
- •Customizing Visual Studio .NET IDE
- •The Options Dialog Box
- •The Customize Dialog Box
- •Summary
- •Index
818 |
Part IX |
BEYOND THE LABS |
|
|
|
|
|
9. Type the following code: |
|
|
using System; |
|
|
using Math; |
|
|
namespace MathClient |
|
|
{ |
/// |
<summary> |
|
|
Y |
{ |
|
|
|
|
/// Summary description for Class1. |
||||
/// </summary> |
|
L |
||
class Class1 |
|
F |
||
|
M |
|
||
|
/// <summary> |
|
|
|
|
A |
|
||
|
|
|
||
/// The main entry point for the application. |
||||
|
E |
|
||
/// </summary> |
|
|
|
|
[STAThread] |
|
|
|
|
|
T |
|
|
|
static void Main(string[] args) |
|
{
MathComp obj=new MathComp(); long lRes=obj.Add(10,20); obj.Extra=false; Console.Write(lRes);
return;
}
}
}
Compile the project and see the output. You can expand on this project further to create a better math application that performs more functions.These steps explain to you the mechanism to create a DLL and access it.
Messaging
The System.Messaging namespace provides classes that allow you to connect to, monitor, and administer message queues on the network and send or receive messages. Before I explain the System.Messaging namespace, it is critical to understand message queuing and certain terms related to messaging.
Team-Fly®
ADVANCED C# CONCEPTS |
Chapter 34 |
819 |
|
|
|
|
|
Benefits of Message Queues
Messaging also provides a powerful and flexible mechanism for interprocess communication between components of a server-based application. The advantages provided by messaging are:
Robustness. Messages are less affected by component failures than direct calls between components, as messages are stored in queues until processed.
Message prioritization. Important messages are received before less important ones.Therefore, you can guarantee adequate response time for critical applications.
Offline capabilities. Messages can be sent to temporary queues and remain there until they are delivered successfully. Moreover, users can continue to perform operations when access to the queue is unavailable. Additional operations can proceed as if the message has already been processed, because the message delivery is guaranteed when the network connection is restored.
Transactional messaging. Several messages can be coupled into a single transaction, ensuring that the messages are delivered in sequence and are successfully retrieved from their destination queue. If any errors occur, the entire transaction is cancelled.
Security. The message queuing technology on which the MessageQueue component is based uses Windows security to provide secure access control, provide auditing, and encrypt and authenticate the messages your component sends and receives.
Limitations
In order to develop MessageQueue components your system must meet the following requirements:
To see queue information in Server Explorer or to access queues programmatically, you must install message queuing on your client computer.
Message queuing can be run in either a domain or a workgroup environment. In the context of message queuing, a domain environment
820 |
Part IX |
BEYOND THE LABS |
|
|
includes domain controllers that provide a directory service such as active |
|
|
|
|
|
directory, and a workgroup environment is any environment that does not |
|
|
provide such a directory service. |
Key Messaging Terms
Before we proceed further, I would like to explain certain key terms.
A message is a unit of data sent from one computer to another. A message can be very simple, consisting of just a string of text, or more complex, possibly involving embedded objects or pictures.
Messages are transmitted to queues. A message queue is a temporary storage area that holds messages while they are in transit. The message queue manager acts as the intermediary in transmitting a message from its source to its destination.The main purpose of a queue is to provide routing and guarantee the delivery of the message. In case the recipient is not available when a message is sent, the queue holds the message until it can be successfully delivered.
Message queuing, Microsoft’s messaging technology, provides messaging and message queue facilities for any applications that have Microsoft Windows installed regardless of whether they are on the same network or whether they are online at the same time.
A message queuing network is a set of computers that are enabled to send messages back and forth to one another. Different computers in the network play different roles to ensure that messaging proceeds smoothly. Some computers provide information to determine how messages are sent, some hold information about the entire network, while others simply send and receive messages.
During message queuing setup, an administrator makes decisions about which servers can communicate with each other and sets up special roles for specific servers. The computers that make up this message queuing network are called sites, and they are connected to one another by site links. Each site link has an associated cost, determined by the administrator, that indicates how quickly messages can be passed across it.
The message queuing administrator also sets up one or more computers in the network that act as routing servers. A routing server makes decisions about how a message is delivered by looking at the cost of various site links and determining the quickest and most efficient way to deliver the message across multiple sites.
ADVANCED C# CONCEPTS |
Chapter 34 |
821 |
|
|
|
|
|
Types of Message Queues
There are two main categories of queues, queues created by users and system queues.
User-Generated Queues
Queues created by users can be any of the following:
Public queues are those that are replicated throughout the message network and can potentially be accessed by all of the computers connected by the network.
Private queues are queues that are not published across the entire network. They are available only on the local computer that contains them. They can be accessed only by applications that know the full path name of the queue.
Administration queues are queues that contain messages acknowledging the delivery of messages sent within a given message queuing network. You specify the administration queue you want your MessageQueue components to use.
Response queues contain response messages that are returned to the sender application when the message is received by the destination application. You specify the response queue you want your MessageQueue components to use.
System Queues
System queues generally fall in one of the following categories:
Journal queues optionally store copies of messages that you send and copies of messages removed from a queue. A single journal queue on each message queuing client stores copies of messages sent from that computer. On the server, a separate journal queue is created for each individual queue. This journal tracks messages removed from that queue.
Dead-letter queues store copies of undeliverable or expired messages. If the message that expired or was undeliverable was a transactional message, it is stored in a special kind of dead-letter queue called a transaction dead-letter queue. Dead letters are stored on the computer on which the message expired.
Report queues contain messages that indicate the route a message took to its destination and can contain test messages. There can be only one report queue per computer.
822 |
Part IX |
BEYOND THE LABS |
|
|
|
Private system queues are a series of private queues that store administrative and notification messages that the system needs to process messaging actions.
Most of the work you do in your applications will involve accessing public queues and their messages. However, you will most likely use several different kinds of the system queues in your day-to-day operations, depending on your application’s need for journal recording, acknowledgement, and other special processing.
Synchronous and Asynchronous Communication
Messages are sent to and received from a queue as separate processes. Therefore, queue communication is inherently asynchronous. You can also receive messages asynchronously by invoking the BeginReceive method and then move on to perform other tasks without waiting for a reply. However, synchronous communication is different from this.
In synchronous communication, the sender of a request waits for a response from the receiver before performing other tasks. The amount of time that the sender must wait depends on the amount of time it takes for the receiver to process the request and send a response.
System.Messaging Namespace
As you know, message queuing is a technology that allows applications running at different times to communicate across heterogeneous networks and systems. Applications send, receive, or read messages from queues.The MessageQueue class is a wrapper around message queuing. There are different versions for different operating environments. System.Messaging namespace provides classes that allow you to connect to, monitor, and administer message queues on the network and send, receive, or read messages.
Message queuing enables developers to build applications that communicate with other programs quickly in a simple and reliable manner. Messaging ensures guaranteed messages delivery and a fail-proof way to carry out your business processes. For example, suppose you have a retail point-of-sale application that must run 24 hours a day, seven days a week. If the database system behind the application goes down, your sales staff might need to start taking orders manually. Using message queuing, you can set up the system so that the orders that cannot be processed during the downtime are automatically put into a queue and processed as soon as the database comes back up.
ADVANCED C# CONCEPTS |
Chapter 34 |
|
823 |
|
|
||||
|
|
|
|
|
You can use an instance of the MessageQueue component to establish connection with existing message queues, examine their contents, and send and receive messages. You can also use Server Explorer of Visual Studio .NET to view message queues on any server to which you have access. You can also add a queue from Server Explorer to your component ’s designer to automatically create a component that is configured to interact with the queue.
MessageQueue Class
MessageQueue class provides members for reading and writing message to the queue.The Send method enables your application to write messages to the queue. This method is overloaded and enables you to specify whether to send your message using a message or any other managed object, including application-specific classes.
The Receive, ReceiveById, and ReceiveByCorrelationId methods provide func-
tionality for reading messages from a queue.These methods support transactional queue processing. These methods also provide overloads with timeout parameters that enable processing to continue if the queue is empty. Because these methods are examples of synchronous processing, they interrupt the current thread until a message is available, unless you specify a timeout.
The Peek method is similar to the Receive method, but it does not cause a message to be removed from the queue when it is read. Because the Peek method does not change the queue contents, there are no overloads to support transactional processing.
The BeginPeek, EndPeek, BeginReceive, and EndReceive methods provide ways to
asynchronously read messages from the queue. They do not interrupt the current thread while waiting for a message to arrive in the queue.
Other methods of the MessageQueue class provide functionality for retrieving lists of queues by specified criteria and determining if specific queues exist.
In addition, MessageQueue class provides methods for creating and deleting message queues, for setting ACL-based access rights, and for working with the connection cache.
The Message class provides detailed control over the information you send to a queue and is the object used when receiving or peeking messages from a queue.
824 |
Part IX |
BEYOND THE LABS |
|
|
|
Besides the message body, the properties of the Message class include acknowledgment settings, format selection, identification, authentication and encryption information, timestamps, and transaction data.
Table 34-1 lists the classes in the System.Messaging namespace hierarchy.
Table 34-1 System.Messaging Namespace Hierarchy
Class |
Description |
AccessControlEntry |
Specifies access rights for a user or a computer |
|
to perform application-specific implementa- |
|
tions of common tasks. |
AccessControlList |
Contains a list of access control entries, speci- |
|
fying access rights for one or more trustees. |
ActiveXMessageFormatter |
Serializes or deserializes primitive data types |
|
and other objects to or from the body of a |
|
message. |
BinaryMessageFormatter |
Serializes or deserializes an object, or a group |
|
of connected objects, to or from the body of a |
|
message, using a binary format. |
DefaultPropertiesToSend |
Specifies the default proper ty values that wil l |
|
be used when sending objects other than |
|
Message instances to a message queue. |
Message |
Provides access to the properties needed to |
|
define a message queuing message. |
MessageEnumerator |
Provides a forward-only cursor to enumerate |
|
through messages in a message queue. |
MessagePropertyFilter |
Controls and selects the properties that are |
|
retrieved when peeking or receiving messages |
|
from a message queue. |
MessageQueue |
Provides access to a queue on a message queu- |
|
ing server. |
MessageQueueAccessControlEntry |
Specifies access rights for a user or a computer |
|
to perform message queuing tasks. |
MessageQueueCriteria |
Filters message queues when performing a |
|
query. |
ADVANCED C# CONCEPTS |
Chapter 34 |
825 |
|||
Table 34-1 System.Messaging Namespace Hierarchy (continued) |
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
Class |
Description |
|
|
|
|
|
|
|
|
|
|
MessageQueueEnumerator |
Provides a forward-only cursor to enumerate |
|
|||
|
through messages in a message queue. |
|
|||
MessageQueueException |
The exception that is thrown if a Microsof t |
|
|||
|
message queuing internal error occurs. |
|
|||
MessageQueueInstaller |
Allows you to install and configure a queue |
|
|||
|
that your application needs in order to run. |
|
|||
MessageQueuePermission |
Allows control of code access permissions for |
|
|||
|
messaging. |
|
|
|
|
MessageQueuePermissionAttribute |
Allows declarative MessageQueue permission |
|
|||
|
checks. |
|
|
|
|
MessageQueuePermissionEntry |
Defines the smallest unit of a code access secu- |
|
|||
|
rity permission set for messaging . |
|
|
|
|
MessageQueuePermissionEntryCollection |
Contains a strongly typed collection of |
|
|||
|
MessageQueuePermissionEntry objects. |
|
|||
MessageQueueTransaction |
Provides a message queuing internal |
|
|||
|
transaction. |
|
|
|
|
MessagingDescriptionAttribute |
Specifies a description for a property or event. |
|
|||
PeekCompletedEventArgs |
Provides data for the PeekCompleted event. |
|
|||
|
When your asynchronous peek operation calls |
|
|||
|
an event handler, an instance of this class is |
|
|||
|
passed to the handler. |
|
|
|
|
ReceiveCompletedEventArgs |
Provides data for ReceiveCompleted event. |
|
|||
Trustee |
Specifies a user account, group account, or |
|
|||
|
logon session to which an access control entry |
|
|||
|
applies. |
|
|
|
|
XmlMessageFormatter |
Serializes and deserializes objects to or from |
|
|||
|
the body of a message , using the XML format. |
|
|||
|
|
|
|
|
|