Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# and the NET Platform, Second Edition - Andrew Troelsen.pdf
Скачиваний:
67
Добавлен:
24.05.2014
Размер:
22.43 Mб
Скачать

Revisiting the Activation Mode of WKO Types

C# and the .NET Platform, Sec nd Edition

 

by Andrew Troelsen

ISBN:1590590554

Recall that WKO types can be configured to function under singleton or single call activation. Currently,

Apress © 2003 (1200 pages)

our server application has registered our WKO to employ singleton activation semantics:

This comprehensive text starts with a brief overview of the C# language and then quickly moves to key technical and

architectural issues for .NET developers.

// Singletons can service multiple clients.

RemotingConfiguration.RegisterWellKnownServiceType(

typeof(SimpleRemotingAsm.RemoteMessageObject),

Table of Contents

"RemoteMsgObj.soap",

C# and the .NET Platform, Second Edition

WellKnownObjectMode.Singleton);

Introduction

Part One - Introducing C# and the .NET Platform

ChapterAgain, singleton1 - The PhilosophyWKOs areofcapable.NET of receiving requests from multiple clients. Thus, singleton objects

Chaptermaintain2 a-oneBuilding-to-manyC# Applicationsrelationship between themselves and the remote clients. To test this behavior for

Partyourself,Two -runThetheC# serverProgrammingapplicationLa guage(if it is not currently running) and launch three separate client

Chaapplicationster 3 - .C#If youLanguagelook atFundamentalsthe output for the server, you will find a single call to the

ChapterRemoteMessageObject's4 - -OrienteddefaultProgrammingconstructorwith(C#Figure 12-12).

Chapter 5 - Exceptions and Object Lifetime

Chapter

 

Chapter

Events

Chapter

Techniques

Part

 

Chapter

 

Chapter

Threads

Figure 12-12: Singleton WKOs are shared among remote clients.

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Now to test the behavior of single call objects, modify the server to register the WKO to support single call

Chapter 12 - Object Serialization and the .NET Remoting Layer activation:

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

// Single call types maintain a 1-to-1 relationship

Chapter 15 - Programming with Windows Forms Controls

// between client and WKO.

Chapter 16 - The System.IO Namespace

RemotingConfiguration.RegisterWellKnownServiceType(

Chapter 17 - Data Access with ADO.NET typeof(SimpleRemotingAsm.RemoteMessageObject),

Part Five - Web Applications and XML Web Services

"RemoteMsgObj.soap",

Chapter 18 - ASP.NET Web Pages and Web Controls

WellKnownObjectMode.SingleCall);

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

IndexOnce you have recompiled and run the server application, again launch three clients. This time you can

see that a new RemoteMessageObject is created for each client request (Figure 12-13).

List of Figures

List of Tables

Figure 12-13: Single call WKOs maintain a one-to-one relationship with their remote clients.

SOURCE The SimpleRemotingAsm, SimpleRemoteObjectServer, and SimpleRemoteObjectClient

CODE projects are located under the Chapter 12 directory.

Deploying the Server to a Remote Machine

C# and the .NET Platform, Second Edition

 

by Andrew Troelsen

ISBN:1590590554

So far so good! At this point, you have just crossed an application and process boundary on a single

Apre s © 2003 (1200 pages)

machine. If you are connected to an additional machine, let's extend this example to allow the client to

This comprehensive text starts with a brief overview of the

interact with the RemoteMessageObjectC# language nd then quicklytype acrossmoves atomachinekey technicalboundaryand . To do so, follow these steps:

architectural issues for .NET developers.

1. On your server machine, create and share a folder to hold your server-side assemblies.

2. Copy the SimpleRemoteObjectServer.exe and SimpleRemotingAsm.dll assemblies to this server-

Table of Contents

side share point.

C# and the .NET Platform, Second Edition

Introduction3. Open your SimpleRemoteObjectClient project workspace and retrofit the activation URL to specify

Part Onethe- Introducingname of theC#remoteand themachine.NET Platform. For example:

Chapter 1 - The Philosophy of .NET

Chapter //2 -GetBuildinga proxyC# Applicationsto remote object.

Part Twoobject- The C#remoteObjProgramming=LanguageActivator.GetObject(

Chapter 3 - C#typeof(SimpleRemotingAsmLanguage Fundam ntals .RemoteMessageObject),

Chapter 4 - Object"http://-OrientedYourRemoteBoxNameProgramming with C#:32469/RemoteMsgObj.soap");

Chapter 5 - Exceptions and Object Lifetime

Chapter 6 - Interfaces and Collections

4. Execute the SimpleRemoteObjectServer.exe application on the server machine.

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

5. Execute the SimpleRemoteObjectClient.exe application on the client machine.

Part Three - Programming with .NET Assemblies

Chapter6. Sit9 back- Understandinggrin. .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Note Activation URLs may specify a machine's IP address in place of its friendly name.

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

LeveragingC#theandTCPthe .NETChannelPlatform, Second Edition

by Andrew Troelsen

ISBN:1590590554

Currently, your remote object is accessible via the HTTP network protocol. As mentioned, this protocol is

Apress © 2003 (1200 pages)

quite firewall-friendly, however the resulting SOAP packets are a bit on the bloated side (given the nature

This comprehensive text starts with a brief overview of the

of XML data representation)C# language. Toandlightenthen quicklythe payload,m ves weto keycantechnicalupdate theandclient and server assemblies to make use of the TCParchitecturalchannel,issuesand thereforefor .NET developersmake use. of the BinaryFormatter type behind the scenes. Here are the relevant updates to the server assembly:

Table Noteof ContentsWhen you are defining an object to be URI-accessible via a TCP endpoint, it is common (but not C# and therequired).NET Platform,to makeSeconduseEditionof the *rem" extension (i.e., remote).

Introduction

Part// OneServer- Introducingadjustments!C# and the .NET Platform

Chapterusing1System- The Philosophy.Runtimeof.Remoting.NET .Channels.Tcp;

Chapter... 2 - Building C# Applications

PartstaticTwo - ThevoidC#Main(string[]Programming Languageargs)

Chapter{ 3 - C# Language Fundamentals

...

Chapter 4 - Object-Oriented Programming with C#

// Create a new TcpChannel

Chapter 5 - Exceptions and Object Lifetime

TcpChannel c = new TcpChannel(32469);

Chapter 6 - Interfaces and Collections

ChannelServices.RegisterChannel(c);

Chapter 7 - Callback Interfaces, Delegates, and Events

// Register a 'well-known' object in single call mode.

Chapter 8 - Advanced C# Type Construction Techniques

RemotingConfiguration.RegisterWellKnownServiceType(

Part Three - Programming with .NET Assemblies

typeof(SimpleRemotingAsm.RemoteMessageObject),

Chapter 9 - Understanding .NET Assemblies

"RemoteMsgObj.rem",

Chapter 10 - Processes, AppDomains, Contexts, and Threads

WellKnownObjectMode.SingleCall);

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Console.ReadLine();

Part Four - Leveraging the .NET Libraries

}

Chapter 12 - Object Serialization and the .NET Remoting Layer Chapter 13 - Building a Better Window (Introducing Windows Forms)

ChapterNotice 14that-weA Betterare nowPaintingregisteringFrameworkSystem(GDI+).Runtime.Remoting.Channels.Tcp.TcpChannel type to the

Chapter.NET Remoting15 - Progrlayermming. AlsowithnoteWindowsthat theFobjectrms ControlsURI has been altered to support a more generic name Chapter(RemoteMsgObj16 - The System.rem) rather.IO Namespacethan the SOAP centric *.soap extension. The client-side updates are equally

as simple:

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter// Client18 - ASPadjustments!.NET Web Pages and Web Controls

Chapterusing19System- ASP.NET.RuntimeWeb Applicati.Remotingns .Channels.Tcp;

Chapter... 20 - XML Web Services

static void Main(string[] args)

Index

{

List of Figures

...

List of Tables

// Create a new TcpChannel

TcpChannel c = new TcpChannel();

ChannelServices.RegisterChannel(c);

//Get a proxy to remote object.

object remoteObj = Activator.GetObject( typeof(SimpleRemotingAsm.RemoteMessageObject),

"tcp://localhost:32469/RemoteMsgObj.rem");

//Use object.

RemoteMessageObject simple = (RemoteMessageObject)remoteObj;

simple.DisplayMessage("Hello from the client!");

Console.WriteLine("Server says: {0}", simple.ReturnMessage());

Console.ReadLine();

}

The only point to be aware of here is that the client's activation URL now must specify the tcp:// channel

qualifier rather than http://. Beyond that, the bulk of the code base is identical to the previous HttpChannel

C# and the .NET Platform, Second Edition

logic.

by Andrew Troelsen

ISBN:1590590554

SOURCE TheApressTCPSimpleRemoteObjectServer© 2003 (1200 pages) and TCPSimpleRemoteObjectClient projects are

CODE

locatedThis comprehensiveunder the Chaptertext starts12 directorywith a brief(bothoverviewprojectsof theuse the SimpleRemotingAsm.dll

 

 

 

 

 

C# language and then quickly moves to key technical and

 

created previously).

 

architectural issues for .NET developers.

Table of Contents

C# and the .NET Platform, Second Edition

Introduction

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

Chapter 3 - C# Language Fundamentals

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

Remoting Configuration# and the .NET Platform,FilesSecond Edition

by Andrew Troelsen

ISBN:1590590554

At this point you have successfully built a distributed application (leveraging two computers) using the .NET

Apress © 2003 (1200 pages)

Remoting layer. One issue you may have noticed in these first examples is that fact that the client and the

This comprehensive text starts with a brief overview of the

server applicationsC#havel nguaa goode anddealthenofquicklyhard-codedmoveslogicto keywithinechnicaltheirandrespective binaries. For example, the server specifies aarchitecturalfixed port ID,issufixeds foractivation.NET developersmode, and. fixed channel type. The client, on the other hand, hard-codes the name of the remote object it is attempting to interact with.

TableAs youf Contentsmight agree, it is wishful thinking to assume that initial design notes remain unchanged once an C#applicationand the .NETis deployedPlatform,. Ideally,S cond detailsEditionsuch as port ID and object activation mode (and whatnot) could be

altered on the fly without needing to recompile and redistribute the client or server code bases. Under the

Introduction

.NET Remoting scheme, all the aforementioned issues can be circumvented using the remoting

Part One - Introducing C# and the .NET Platform

configuration file.

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

As you recall from Chapter 9, *.config can be used to provide hints to the CLR regarding the loading of

Part Two - The C# Programming Language

externally referenced assemblies. The same *.config files can be used to inform the CLR of a number of

Chapter 3 - C# Language Fundamentals

remoting-related details, on both the client side and the server side.

Chapter 4 - Object-Oriented Programming with C#

ChapterWhen building5 - Exceptionsa remotingand*Object.configLiffile,timethe <system.runtime.remoting> element is used to hold various

Chapterremoting6 -centric- Interfacesdetailsand. DoCollbectionsaware that if you are building an application that already has a *.config file Chapterthat specifies7 - CallbackassemblyInterfaces,resolutionDelegatedetails,andyou Evarentsfree to add remoting elements within the same file. Thus,

a single *.config file that contains remoting and binding information would look something like this:

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Chapter<configuration>9 - Understanding .NET Assemblies

Chapter <system10 - Processes,.runtimeAppDomains,.remoting>Contexts, and Threads

Chapter 11 - Type<! Reflectio-- configure, Late Binding,clienta d Attribute/ server-BasedremotingPr grammingsettings here -- >

Part Four</system- Leveraging.runtimethe .NET.Librariesremoting>

<runtime>

Chapter 12 - Object Serialization and the .NET Remoting Layer

<! -- binding assembly settings here -- >

Chapter 13 - Building a Better Window (Introducing Windows Forms)

</runtime>

Chapter 14 - A Better Painting Framework (GDI+)

</configuration>

Chapter 15 - Programming with Windows Forms Controls Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

If your configuration file has no need to specify assembly binding logic, you can omit the <runtime> element

Part Five - Web Applications and XML Web Services

and make use of the following skeleton *config file:

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

<configuration>

Chapter 20 - XML Web Services

<system.runtime.remoting>

Index

<! -- configure client / server remoting settings here -- >

List of Figures

</system.runtime.remoting>

List of Tables

</configuration>

Building Server-Side *.config Files

Server-side configuration files allow you to declare the objects that are to be reached via remote invocations as well as channel and port information. Basically, using the <service>, <wellknown>, and <channels> elements, you are able to replace the following server-side logic:

// Hard coded HTTP server logic.

HttpChannel c = new HttpChannel(32469);

ChannelServices.RegisterChannel(c);

RemotingConfiguration.RegisterWellKnownServiceType(

typeof(SimpleRemotingAsm.RemoteMessageObject),

"RemoteMsgObj.soap",

WellKnownObjectMode.Singleton);

C# and the .NET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

with the followingApress*.config© 2003file: (1200 pages)

This comprehensive text starts with a brief overview of the

C# language and then quickly moves to key technical and

<configuration>

architectural issues for .NET developers.

<system.runtime.remoting>

<application>

<service>

Table of Contents

<wellknown

C# and the .NET Platform, Second Edition

mode="Singleton"

Introduction

type="SimpleRemotingAsm.RemoteMessageObject, SimpleRemotingAsm"

Part One - Introducing C# and the .NET Platform

objectUri="RemoteMsgObj.soap"/>

Chapter 1 - The Philosophy of .NET

</service>

Chapter 2 - Building C# Applications

<channels>

Part Two - The C# Programming Language

<channel ref="http"/>

Chapter 3 - C# Language Fundamentals

</channels>

Chapter 4 - Object-Oriented Programming with C#

</application>

Chapter 5 - Exceptions and Object Lifetime

</system.runtime.remoting>

Chapter 6 - Interfaces and Collections

</configuration>

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

Notice that much of the relevant server-side remoting information is wrapped within the scope of the

Part Three - Programming with .NET Assemblies

<service> (not server) element. The child <wellknown> element makes use of three attributes (mode, type,

Chapter 9 - Understanding .NET Assemblies

and objectUri) to specify the well-known object to register with the .NET Remoting layer. The child

Chapter 10 - Processes, AppDomains, Contexts, and Threads

<channels> element contains any number of <channel> elements that allow you to define the type of

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

channel (in this case HTTP) to open on the server. TCP channels would simply make use of the "tcp" string

Part Four - Leveraging the .NET Libraries

token in place of "http".

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

As the SimpleRemoteObjectServer.exe.config file contains all the necessary information, the server-side

Chapter 14 - A Better Painting Framework (GDI+)

Main() method cleans up considerably. All you are required to do is make a single call to

ChapterRemotingConfiguration15 - Pro ramming with Windows Forms Controls

.Configure(), and specify the name of your configuration file.

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET static void Main(string[] args)

Part Five - Web Applications and XML Web Services

{

Chapter 18 - ASP.NET Web Pages and Web Controls

// Register a 'well-known' object using a *.config file.

Chapter 19 - ASP.NET Web Applications

RemotingConfiguration.Configure("SimpleRemoteObjectServer.exe.config");

Chapter 20 - XML Web Services

Console.WriteLine("Server started! Hit enter to end");

Index Console.ReadLine();

List} of Figures

List of Tables

Building Client-Side *.config Files

Clients are also able to leverage remoting-centric *.config files. Unlike a server-side configuration file, clientside configuration files make use of the <client> element to identify the name of the well-known object the caller wishes to interact with. In addition to providing the ability to dynamically change the remoting information without a need to recompile the code base, client-side *.config files allow you to create the proxy type directly using the C# "new" keyword, rather than the Activator.GetObject() method. Thus, if you have the following client-side *.config file:

<configuration>

<system.runtime.remoting>

<application>

<client displayName = "SimpleRemoteObjectClient">

<wellknown

type="SimpleRemotingAsm.RemoteMessageObject, SimpleRemotingAsm"

C# and the .NET Platform, Second Edition url="http://localhost:32469/RemoteMsgObj.soap"/>

by Andrew Troelsen

ISBN:1590590554

</client>

 

Apress © 2003 (1200 pages)

 

<channels>

 

This comprehensiveref="http"/>text starts with a brief overview of the

<channel

C# language and then quickly moves to key technical and

</channels>

architectural issues for .NET developers.

</application>

</system.runtime.remoting>

</configuration>

Table of Contents

C# and the .NET Platform, Second Edition

Introduction

You are able to update the client's Main() method as follows:

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

static void Main(string[] args)

Chapter 2 - Building C# Applications

{

Part Two - The C# Programming Language

RemotingConfiguration.Configure("SimpleRemoteObjectClient.exe.config");

Chapter 3 - C# Language Fundamentals

// Using *config file, the client is able to directly 'new' the type.

Chapter 4 - Object-Oriented Programming with C#

RemoteMessageObject simple = new RemoteMessageObject();

Chapter 5 - Exceptions and Object Lifetime simple.DisplayMessage("Hello from the client!");

Chapter 6 - Interfaces and Collections

Console.WriteLine("Server says: {0}", simple.ReturnMessage());

Chapter Console7 - Ca lbackWriteLine("ClientIn erfaces, Delegates, and Events

. started! Hit enter to end");

Chapter Console8 - Advanced.ReadLine();C# Type Construction Techniques

Part} Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Of course, when you run the application, the output is identical. If the client wishes to make use of the TCP

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

channel, the "url" property of the <wellknown> element and <channel> ref property must make use of the

Part Four - Leveraging the .NET Libraries

"tcp"" token in place of "http."

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

SOURCE The SimpleRemoteObjectServerWithConfig and SimpleRemoteObjectClientWithConfig

Chapter 14 - A Better Painting Framework (GDI+)

CODE projects are located under the Chapter 12 subdirectory (both of which make use of the

Chapter 15 - Programming with Windows Forms Controls

SimpleRemotingAsm.dll created previously).

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

Working withC# andMBVthe .ObjectsNET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

Our first remoting applications allowed client-side access to a single WKO type. Recall that WKO types are

Apress © 2003 (1200 pages)

(by definition) MBR types, and therefore client access takes place via an intervening proxy. In contrast, MBV

This comprehensive text starts with a brief overview of the

types are local copiesC# languageof a serverand-sidethen type,quicklywhichmovesaretotypicallykey technicalreturnedandfrom a public member of an MBR type. Although youarchitecturalalready knowissueshowforto.NETconfiguredevelopersan MBV. type (mark a class with the [Serializable] attribute), we have not yet seen an example of MBV types in action. To illustrate the interplay of MBR and MBV types, let's see another example which will involve three assemblies:

Table of Contents

C#andThethegeneral.NET Platform,assemblySecondnamedE itionCarGeneralAsm.dll

Introduction

The client assembly named CarProviderClient.exe

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

The server assembly named CarProviderServer.exe

Chapter 2 - Building C# Applications

PartAs youTwomight- T e C#assume,Programmingthe codeLanguagebehind the client and server applications is more or less identical to the Chapterprevious3 example,- C# LanguageespeciallyFundamensince theseals applications will again make use of *.config files. Nevertheless, let's

step through the process of building each assembly one at a time.

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

ChapterBuilding6 - IntheerfacesCarsnd CollectionsGeneral Assembly

Chapter 7 - Callback Interfaces, Delegates, and Events

At the beginning of this chapter (during our examination of object serialization), you created a type named

Chapter 8 - Advanced C# Type Construction Techniques

JamesBondCar. The CarGeneralAsm.dll code library will reuse this type (in addition to the dependent Radio

Part Three - Programming with .NET Assemblies

and Car types), so begin by using the Project | Add Existing Item... menu command, and include these *.cs

Chapter 9 - Understanding .NET Assemblies

files into this new Class Library project. Given that each of these types have already been marked with the

Chapter 10 - Processes, AppDomains, Contexts, and Threads

[Serializable] attribute, they are ready to be marshaled by value to a remote client.

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

All we need now is an MBR type which provides access to the JamesBondCar type. To make things a bit

Chapter 12 - Object Serialization and the .NET Remoting Layer

more interesting, however, our MBR object (CarProvider) will maintain an ArrayList of JamesBondCar types.

Chapter 13 - Building a Better Window (Introducing Windows Forms)

CarProvider will also define two members, which allow the caller to obtain a specific JamesBondCar, as well

Chapter 14 - A Better Painting Framework (GDI+)

as receive the entire ArrayList of types. Here is the complete code for our new class type:

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

namespace CarGeneralAsm

Chapter 17 - Data Access with ADO.NET

{

Part Five - Web Applications and XML Web Services

// This type is an MBR object which provides

Chapter 18 - ASP.NET Web Pages and Web Controls

// access to related MBV types.

Chapter 19 - ASP.NET Web Applications

public class CarProvider : MarshalByRefObject

Chapter 20 - XML Web Services

{

Index

List of Figures

List of Tables

private ArrayList theJBCars = new ArrayList();

// Add some cars to the array list.

public CarProvider()

{

Console.WriteLine("Car provider created");

theJBCars.Add(new JamesBondCar("QMobile", 140, true, true)); theJBCars.Add(new JamesBondCar("Flyer", 140, true, false)); theJBCars.Add(new JamesBondCar("Swinner", 140, false, true)); theJBCars.Add(new JamesBondCar("BasicJBC", 140, false, false));

}

// Get all the JamesBondCars.

public ArrayList GetAllAutos()

{ return theJBCars; }

// Get one JamesBondCar.

public JamesBondCar GetJBCByIndex(int i)

{ return (JamesBondCar)theJBCars[i]; }

}

}

Chapter 3 - C# Language Fundamentals
Part Two - The C# Programming Language
Chapter 2 - Building C# Applications

C# and the .NET Platform, Second Edition

 

by Andrew Troelsen

ISBN:1590590554

Notice the GetAllAutos() method returns the internal ArrayList type. The obvious question is how this member

Apress © 2003 (1200 pages)

of the System.Collections namespace is marshaled back to the caller. If you look up this type using online

This comprehensive text starts with a brief overview of the

Help, you may be surprise to find that ArrayList has been decorated with the [Serializable] attribute:

C# language and then quickly moves to key technical and

architectural issues for .NET developers.

[Serializable]

public class ArrayList : IList, ICollection,

TableIEnumerable,of Contents ICloneable{...}

C# and the .NET Platform, Second Edition

Introduction

Therefore, the entire contents of the ArrayList type will be marshaled by value to the caller (provided the

Part One - Introducing C# and the .NET Platform

contained types are also serializable)! This brings up a very good point regarding .NET Remoting and

Chapter 1 - The Philosophy of .NET

members of the base class libraries. In addition to the custom MBV and MBR types you may create yourself, do understand that any type in the base class libraries which is decorated with the [Serializable] attribute is able to function as an MBV type in the .NET Remoting architecture. Likewise, any type which derives (directly

or indirectly) from MarshalByRefObject will function as an MBR type.

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

Building the Server Assembly

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

The server host assembly (CarProviderServer.exe) has the following logic within Main():

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

using System;

Chapter 9 - Understanding .NET Assemblies

using System.Runtime.Remoting;

Chapter 10 - Processes, AppDomains, Contexts, and Threads using System.Runtime.Remoting.Channels;

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming using System.Runtime.Remoting.Channels.Http;

Part Four - Leveraging the .NET Libraries

using CarGeneralAsm;

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

namespace CarProviderServer

Chapter 14 - A Better Painting Framework (GDI+)

{

 

 

Chapter 15 - Programming with Windows Forms Controls

class CarServer

 

Chapter 16 - The System.IO Namespace

 

{

 

 

Chapter 17 - Data Access with ADO.NET

 

 

static void Main(string[] args)

Part Five - Web Applications and XML Web Services

 

{

 

Chapter 18 - ASP.NET Web Pages and Web

rols

 

RemotingConfiguration.Configure("CarProviderServer.exe.config");

Chapter 19 - ASP.NET ConsoleWeb Applications.WriteLine("Car server started! Hit enter to end");

Chapter 20 - XML WebConsoleServices .ReadLine();

Index

}

 

List of Figures}

 

 

List} of Tables

 

 

The related *.config file is just about identical to the previous server side *.config file you created in the previous example. The only point of interest is to define an object URI value which makes sense for the CarProvider type (pick your channel of choice):

<configuration>

<system.runtime.remoting>

<application>

<service>

<wellknown mode="Singleton"

type="CarGeneralAsm.CarProvider, CarGeneralAsm"

objectUri="carprovider.soap" />

</service>

<channels>

<channel ref="http" port="32469" />

C# and the .NET Platform, Second Edition

</channels>

by Andrew Troelsen

ISBN:1590590554

</application>

 

Apress © 2003 (1200 pages)

 

</system.runtime.remoting>

 

This comprehensive text starts with a brief overview of the

</configuration>

C# language and then quickly moves to key technical and architectural issues for .NET developers.

Building the Client Assembly

Table of Contents

Last but not least, we have the client application which will make use of the MBR CarProvider type in order to

C# and the .NET Platform, Second Edition

obtain discrete JamesBondCars types as well as the ArrayList type. Once we obtain a type from the

Introduction

CarProvider, we'll send them into the UseCar() helper function from processing:

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Chapterusing2System;- Building C# Applications

PartusingTwo -SystemThe C#.ProgrammingRuntime.Remoting;Language

using System.Runtime.Remoting.Channels;

Chapter 3 - C# Language Fundamentals

using System.Runtime.Remoting.Channels.Http;

Chapter 4 - Object-Oriented Programming with C#

using CarGeneralAsm;

Chapter 5 - Exceptions and Object Lifetime

using System.Collections;

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

namespace CarProviderClient

Chapter 8 - Advanced C# Type Construction Techniques

{

Part Three - Programming with .NET Assemblies

class CarClient

Chapter 9 - Understanding .NET Assemblies

{

Chapter 10 - Processes, AppDomains, Contexts, and Threads

private static void UseCar(JamesBondCar c)

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

 

{

 

Part Four - Leveraging the .NET Libraries

 

 

Console.WriteLine("-> Name: {0}", c.PetName);

Chapter 12 - Object Serialization and the .NET Remoting Layer

 

Console.WriteLine("-> Max speed: {0}", c.MaxSpeed);

Chapter 13 - Building a Better Window (Introducing Windows Forms)

 

Console.WriteLine("-> Sea worthy? : {0}", c.isSeaWorthy);

Chapter 14 - A Better Painting Framework (GDI+)

 

 

Console.WriteLine("-> Flight worthy? : {0}", c.isFlightWorthy);

Chapter 15 - Programming with Windows Forms Controls

 

Console.WriteLine();

 

Chapter 16 - The System.IO Namespace

 

 

c.TurnOnRadio(true);

 

Chapter 17 - Data} Access with ADO.NET

 

Part Five - WebstaticApplicationsvoidandMain(string[]XML Web Services args)

Chapter 18 - ASP{ .NET Web Pages and Web Controls

.Configure("CarProviderClient.exe.config");

Chapter 19 - ASP.NET RemotingConfigurationWeb Applicatio s

Chapter 20 - XML Web//ServicesMake the car provider.

Index

CarProvider cp = new CarProvider();

List of Figures

// Get first JBC.

 

List of Tables

JamesBondCar qCar = cp.GetJBCByIndex(0);

 

// Get all JBCs.

 

ArrayList allJBCs = cp.GetAllAutos();

// Use first car.

UseCar(qCar);

// Use all cars in ArrayList foreach(JamesBondCar j in allJBCs)

UseCar(j);

Console.WriteLine("Client started! Hit enter to end");

Console.ReadLine();

}

}

}

The client side *.config is also what you would expect. Simply update the activation URL:

Chapter 10 - Processes, AppDomains, Contexts, and Threads
Chapter 9 - Understanding .NET Assemblies
Part Three - Programming with .NET Assemblies

<configuration>

C# and the .NET Platform, Second Edition

<system.runtime.remoting>

by Andrew Troelsen

ISBN:1590590554

<application>

 

Apress © 2003 (1200 pages)

<client displayName = "CarClient">

This comprehensive text starts with a brief overview of the

<wellknown

C# language and then quickly moves to key technical and type="CarGeneralAsm.CarProvider, CarGeneralAsm"

architectural issues for .NET developers. url="http://localhost:32469/carprovider.soap"/>

</client>

<channels>

Table of Contents

<channel ref="http"/>

C# and the .NET Platform, Second Edition

</channels>

Introduction

</application>

Part One - Introducing C# and the .NET Platform

</system.runtime.remoting>

Chapter 1 - The Philosophy of .NET

</configuration>

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

Chapter 3 - C# Language Fundamentals

Now, run your server and client applications (in that order, of course) and observe the output. Your client-side Chapterconsole4window- Objectwill-Orientedwhirl throughPro rammingthe JamesBondCarswith C# and print out the statistics of each type. Recall that as

Chapteryou interact5 - Exceptionswith the ArrayListand ObjectandLifetimeJamesBondCar types you are operating on their members within the

Chapterclient's6application- Interfacesdomain,and Collectionsas they have both been marked with the [Serializable] attribute.

Chapter 7 - Callback Interfaces, Delegates, and Events

To prove that point, update the UseCar() helper function to call the TurnOnRadio() method on the incoming

Chapter 8 - Advanced C# Type Construction Techniques

JamesBondCar. Now, run the server and client applications once again. Notice that the message box appears on the client machine! Had the Car, Radio, and JamesBondCar types been configured as MBR types, the server would be the machine displaying the message box prompts. If you wish to verify this, derive

each type from MarshalByRefObject, and recompile all three assemblies (to ensure VS .NET copies the

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

latest CarGeneralAsm.dll into the client's and server's application directory). When you run the application

Part Four - Leveraging the .NET Libraries

once again, the message boxes appear on the remote machine.

Chapter 12 - Object Serialization and the .NET Remoting Layer

ChapterSOURCE13 - BuildingThea BetterCarGeneralAsm,Window (IntroducingCarProviderServer,Windows Forms)and CarProviderClient projects are located

ChapterCODE14 - A BetterunderPaintingtheFrameworkChapter 12(GDI+)subdirectory.

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

UnderstandingC# andClientthe .NET-ActivatedPla form, SecondObjectsEdition (CAO)

by Andrew Troelsen

ISBN:1590590554

All of our current remoting examples have made use of so-called well-known objects (which again, sometimes

Apress © 2003 (1200 pages)

go by the term server-activated objects). Recall that WKOs have the following characteristics:

This comprehensive text starts with a brief overview of the

C# language and then quickly moves to key technical and

WKOs can be configured either as singleton or single call. architect ral issues for .NET devel pers.

WKOs can only be activated using the type's default constructor.

Table of Contents

WKOs are instantiated on the server on the first client-side member invocation.

C# and the .NET Platform, Second Edition

IntroductionCAO types on the other hand, can be instantiated using any constructor on the type and are created at the poin

ParttheOneclient- Introducingmakes use C#of theandC#the"new".NET Platformkeyword or Activator type. Furthermore, the lifetime of CAO types is

Chaptermonitored1 -byThethePhilosophy.NET leasingof .NETmechanism. Do be aware that when you configure a CAO type, the .NET

ChapterRemoting2 -layerBuildingwill generateC# Applicationsspecific CAO remote object to service each client. Again, the big distinction is th

PartfactTwothat-CAOsThe C#areProgralwaysmmingaliveLanguage(and therefore stateful) beyond a single method invocation.

Chapter 3 - C# Language Fundamentals

To illustrate the construction, hosting, and consumption of CAO types, let's retrofit our previous automobile-

Chapter 4 - Object-Oriented Programming with C#

centric general assembly. Assume that our MBR CarProvider class has defined an additional constructor that

Chapter 5 - Exceptions and Object Lifetime

allows the client to pass in an array of JamesBondCar types that will be used to populate the internal ArrayList:

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

public class CarProvider : MarshalByRefObject

Chapter 8 - Advanced C# Type Construction Techniques

{

Part Three - Programming with .NET Assemblies

private ArrayList theJBCars = new ArrayList();

Chapter 9 - Understanding .NET Assemblies

public CarProvider(JamesBondCar[] theCars)

Chapter 10 - Processes, AppDomains, Contexts, and Threads

{

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Console.WriteLine("Car provider created with custom ctor");

Part Four - Leveraging the .NET Libraries

theJBCars.AddRange(theCars);

Chapter 12 - Object Serialization and the .NET Remoting Layer

}

Chapter 13 - Building a Better Window (Introducing Windows Forms)

...

Chapter 14 - A Better Painting Framework (GDI+)

}

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

In order to allow the caller to activate the CarProvider using our new constructor syntax, we need to build a serv

Chapter 17 - Data Access with ADO.NET

application that registers CarProvider as a CAO type rather than a WKO type. This may be done

Part Five - Web Applications and XML Web Services

programmatically (a la the RemotingConfiguration.RegisterActivatedServiceType() method) or using a server-

Chapter 18 - ASP.NET Web Pages and Web Controls

side *.config file. If you wish to hard-code the name of the CAO object within the host server's code base, all yo

Chapter 19 - ASP.NET Web Applications

need to do is pass in the type information of the type(s) (after creating and registering a channel) as follows:

Chapter 20 - XML Web Services

Index

// Hard code the fact that CarProvider is a CAO type.

List of Figures

RemotingConfiguration.RegisterActivatedServiceType(

List of Tables

typeof(CAOCarGeneralAsm.CarProvider));

If you would rather leverage the *.config file, replace the <wellknown> element with the <activated> element as

follows:

<configuration>

<system.runtime.remoting>

<application>

<service>

<activated type = "CAOCarGeneralAsm.CarProvider,

CAOCarGeneralAsm"/>

</service>

<channels>

<channel ref="http" port="32469" />

</channels>

C# and the .NET Platform, Second Edition

 

</application>

ISBN:1590590554

by Andrew Troelsen

</system.runtime.remoting>

 

Apress © 2003 (1200 pages)

 

</configuration>

 

This comprehensive text starts with a brief overview of the

C# language and then quickly moves to key technical and

architectural issues for .NET developers.

Finally, we need to update the client application, not only by way of the *.config file (or programmatically in the

code base) to request access to the remote CAO, but to indeed trigger the custom constructor of the CarProvid

type. Here are the relevant updates to the client side Main() method:

Table of Contents

C# and the .NET Platform, Second Edition

static void Main(string[] args)

Introduction

{

Part One - Introducing C# and the .NET Platform

Chapter //1

-ReadThe Philosophyupdatedof*.NET.config file.

Chapter

RemotingConfiguration.Configure("CAOCarProviderClient.exe.config");

2

- Building C# Applications

 

// Create array of types to pass to provider.

Part Two - The C# Programming Language

Chapter

JamesBondCar[] cars =

3

- C# Language Fundamentals

 

{

 

Chapter

4

- Object-Oriented Programming with C#

 

 

new JamesBondCar("One", 100, false, false),

Chapter

5

- Exceptions and Object Lifetime

 

 

new JamesBondCar("Two", 100, false, false),

Chapter

6

- Interfaces and Collections

 

 

new JamesBondCar("Three", 100, false, false)

Chapter

7

- Callback Interfaces, Delegates, and Events

 

};

 

Chapter

8

- Advanced C# Type Construction Techniques

 

// Now trigger the custom ctor.

Part Three - ogramming with .NET Assemblies

Chapter...

CarProvider cp = new CarProvider(cars);

9

- Understanding .NET Assemblies

Chapter}

10

- Processes, AppDomains, Contexts, and Threads

Chapter

11

- Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

The updated client side *.config file also makes use of the <activated> element, as opposed to <wellknown>. In

Chapter 12 - Object Serialization and the .NET Remoting Layer

addition, however, the <client> element now requires the url property to define the location of the registered CA

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Recall that when the server registered the CarProvider as a WKO, the client specified such information within t

Chapter 14 - A Better Painting Framework (GDI+)

<wellknown> element.

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

<configuration>

Chapter 17 - Data Access with ADO.NET

<system.runtime.remoting>

Part Five - Web Applications and XML Web Services

<application>

Chapter 18 - ASP.NET Web Pages and Web Controls

<client displayName = "CarClient"

Chapter 19 - ASP.NET Web Applications

url = "http://localhost:32469">

Chapter 20 - XML Web Services

<activated type = "CAOCarGeneralAsm.CarProvider, CAOCarGeneralAsm"

Index

</client>

List of Figures <channels>

List of Tables

<channel ref="http"/>

 

 

</channels>

</application>

</system.runtime.remoting>

</configuration>

If you would rather hard-code the client's request to the CAO type, you can make use of the

RegistrationServices.RegisterActivatedClientType() method as follows:

static void Main(string[] args)

{

// Use hard coded values.

RemotingConfiguration.RegisterActivatedClientType(

typeof(CAOCarGeneralAsm.CarProvider),

"http://localhost:32469");

...

}

C# and the .NET Platform, Second Edition

 

by Andrew Troelsen

ISBN:1590590554

 

 

Apress © 2003 (1200 pages)

 

If you were to nowThisexecutecomprehensivethe updatedtextserverstarts andwithclienta briefassemblies,ov rview of youthe would be pleased to find that you are

 

C# langu ge and then quickly moves to key technical and

able to pass your custom array of JamesBondCar types to the remote CarProvider via the overloaded

constructor.

architectural issues for .NET developers.

 

SOURCE

The CAOCarGeneralAsm, CAOCarProviderServer, and CAOCarProviderClient projects are

Table of Contents

located under the Chapter 12 subdirectory.

CODE

C# and the .NET Platform, Second Edition

Introduction

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

Chapter 3 - C# Language Fundamentals

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

The Lease-C#Basedand theLifetime.NET Platform,of CAO/WKOSecond Edition -Singleton Objects

by Andrew Troelsen

ISBN:1590590554

As you have seen, WKO types configured with single-call activation are only alive for the duration of the current

Apress © 2003 (1200 pages)

method call. Given this fact, WKO single-call types are stateless entities. As soon as the current invocation has

This comprehensive text starts with a brief overview of the completed, the WKOC# languagesingle-callndtypethenisquia candidatekly mov sforto garbagekey technicalcollectionand .

architectural issues for .NET developers.

On the other hand, CAO types and WKO types which have been configured to use singleton activation are both by their nature, stateful entities. Given these two object configuration settings, the question which must be aske

Tableis: Howf Contentsdoes the server process know when to destroy these MBR objects? Clearly, it would be a huge bother i C#theandserverthe .machineNET Platform,garbageSecondcollectedEditionMBR objects that were currently in use by a remote client. If the server

machine waits too long to release its set of MBR types, this may place undo stress on the system, especially if t

Introduction

MBR object(s) in question maintain valuable system resources (database connections, unmanaged types, and

Part One - Introducing C# and the .NET Platform

whatnot).

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

Unlike classic DCOM, the .NET Remoting layer obviously does not make use of an interface-based reference

Part Two - The C# Programming Language

counting mechanism (or occasional pings) to control object lifetime. Rather, the lifetime of a CAO or WKO-

Chapter 3 - C# Language Fundamentals

singleton MBR type is governed by a lease time that is tightly integrated with the .NET garbage collector. If the

Chapter 4 - Object-Oriented Programming with C#

lease time of a CAO or WKO-singleton MBR type expires, the object is ready to be garbage collected on the ne

Chapter 5 - Exceptions and Object Lifetime

collection cycle. Like any .NET type, if the remote object has overridden System.Object.Finalize() (via the C#

Chapter 6 - Interfaces and Collections

destructor syntax), the .NET runtime will indeed trigger the finalization logic.

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

The Default Leasing Behavior

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

CAO and WKO-singleton MBR types have what is known as a default lease, which lasts for 5 minutes. If the

Chapter 10 - Processes, AppDomains, Contexts, and Threads

runtime detects 5 minutes of inactivity have passed for a CAO or WKO-singleton MBR type, the assumption is

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

that the client is no longer making use of the entity (or perhaps is no longer running), and therefore the remote PartobjectFourmay- Levberaginggarbagethecollected.NET Libraries. Of course, this does not imply that a given CAO or WKO-singleton object is Chapterautomatically12 - ObjectmarkedSerializationfor garbageandcollectionthe .NET Remotingafter 5 minutes!Layer The truth of the matter is that there are many way

Chapterto alter13the-timBuildingofatheBettdefaultr Windowlease(Introducing. Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

First and foremost, anytime the remote client invokes a member of the remote CAO or WKO-singleton MBR typ

Chapter 15 - Programming with Windows Forms Controls

the lease is renewed back to its 5 minute limit. In addition to the automatic client-invocation-centric renew policy

Chapter 16 - The System.IO Namespace

the .NET runtime provides three additional alternatives:

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

*.config files can be authored that override the default lease settings for a given remote object.

Chapter 18 - ASP.NET Web Pages and Web Controls

ChapterServer19 --sideASP.NETleaseWebsponsorsApplicatiocansbe used to act on behalf of a remote object whose lease time has expired.

Chapter 20 - XML Web Services

Client-side lease sponsors can be used to act on behalf of a remote object whose lease time has expired.

Index

List of Figures

We will check out these options over the next several sections, but for the time being let's come to understand

List of Tables

the default lease settings of a remote type. Recall that the MarshalByRefObject base class defines a member named GetLifetimeService(). This method returns a reference to an internally implemented object that support the System.Runtime.Remoting.Lifetime.ILease interface. As you would guess, the ILease interface can be used to interact with the leasing behavior of a given CAO or WKO-singleton type. Here is the formal definition:

public interface ILease

{

TimeSpan CurrentLeaseTime { get; }

LeaseState CurrentState { get; }

TimeSpan InitialLeaseTime { get; set; }

TimeSpan RenewOnCallTime { get; set; }

TimeSpan SponsorshipTimeout { get; set; }

void Register(System.Runtime.Remoting.Lifetime.ISponsor obj); void Register(System.Runtime.Remoting.Lifetime.ISponsor obj,

TimeSpan renewalTime);

TimeSpan Renew(TimeSpan renewalTime);

void Unregister(System.Runtime.Remoting.Lifetime.ISponsor obj);

}

C# and the .NET Platform, Second Edition

 

by Andrew Troelsen

ISBN:1590590554

 

 

Apress © 2003 (1200 pages)

 

The ILease interfaceThis notc mprehensiveonly allowstextyou startsto obtainwithinformationa brief overviewregardingof thethe current lease (via CurrentLeaseTime,C# CurrentState,language nd thenand InitialLeaseTime)quickly moves to keybuttechnicalalso providesand the ability to build lease sponsors

architectural issues for .NET developers.

(more later). Table 12-9 documents the role of each ILease member.

Table 12-9: Members of the ILease Interface

Table of Contents

C#Memberand the .NETof Platform, SecondMeaningEditionin Life

IntroductionIlease

 

 

 

 

 

 

 

 

 

 

Part One - Introducing C#

and the .NET Platform

 

 

 

 

CurrentLeaseTime

 

Gets the amount of time remaining before the object deactivates if it does not

 

 

Chapter 1

- The Philosophy

 

of .NET

 

 

 

 

 

 

 

receive further method invocations.

 

 

 

 

Chapter 2

- Building C#

 

Applications

 

 

 

 

 

 

 

 

 

CurrentState

 

Gets the current state of the lease, represented by the LeaseState

 

 

Part Two - The C# Programming Language

 

 

Chapter 3

- C# Language Fuendamentalsumeration.

 

 

 

 

 

 

 

 

 

 

Chapter 4

- Object-Oriented

 

Programming with C#

 

 

 

 

InitialLeaseTime

 

Gets or sets the initial amount of time for a given lease. The initial lease time of

 

 

 

Chapter 5

- Exceptions and

Object Lifetime

 

 

 

 

Chapter 6

- Interfaces and

an object is the amount of time following the initial activation before the lease

 

 

 

Collections

 

 

 

 

 

 

 

expires if no other method calls occur.

 

 

 

 

Chapter 7

- Callback Interfaces, Delegates, and Events

 

 

 

 

 

 

ChapterRenewOnCallTime8 - Advanced C# TypeGetsConstructionor sets the amountTechniquesof time by which a call to the remote object increases

 

 

Part Three - Programming

 

withthe.NETCurrentLeaseTime.Assemblies

 

 

 

 

 

 

 

 

 

 

 

Chapter 9

- Understanding

 

.NET Assemblies

 

 

 

 

SponsorshipTimeout

 

Gets or sets the amount of time to wait for a sponsor to return with a lease

 

 

 

Chapter 10

- Processes,

 

AppDomains, Contexts, and Threads

 

 

 

 

 

 

 

renewal time.

 

 

 

 

Chapter 11

- Type Reflection,

 

Late Binding, and Attribute-Based Programming

 

 

 

 

 

 

 

 

 

Register()

 

Overloaded. Registers a sponsor for the lease.

 

 

Part Four - Leveraging the

 

.NET Libraries

 

 

 

 

 

 

 

 

 

 

 

Chapter 12

- Object Serialization and the .NET Remoting Layer

 

 

 

 

Renew()

 

 

Renews a lease for the specified time.

 

 

 

 

 

 

 

 

Chapter 13

- Building a Better Window (Introducing Windows Forms)

 

 

 

 

Unregister()

 

Removes a sponsor from the sponsor list.

 

 

 

Chapter 14

- A Better Painting Framework (GDI+)

 

 

 

 

 

Chapter 15

- Programming with Windows Forms Controls

To illustrate the characteristics of the default lease of a CAO or WKO-singleton remote object, assume that our

Chapter 16 - The System.IO Namespace

current CAOCarGeneralAsm project has defined a new type named LeaseInfo. LeaseInfo supports a static

Chapter 17 - Data Access with ADO.NET

member named LeaseStats() which dumps select statistics regarding the current lease for the CarProvider type

Part Five - Web Applications and XML Web Services

to the server side console window (be sure to specify a "using" directive for the

Chapter 18 - ASP.NET Web Pages and Web Controls

System.Runtime.Remoting.Lifetime namespace to inform the compiler where the ILease type is defined):

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

internal class LeaseInfo

Index

{

List of Figures

public static void LeaseStats(ILease itfLease)

List of Tables

{

Console.WriteLine("***** Lease Stats *****");

Console.WriteLine("Lease state: {0}", itfLease.CurrentState);

Console.WriteLine("Initial lease time: {0}:{1}",

itfLease.InitialLeaseTime.Minutes,

itfLease.InitialLeaseTime.Seconds); Console.WriteLine("Current lease time: {0}:{1}",

itfLease.CurrentLeaseTime.Minutes,

itfLease.CurrentLeaseTime.Seconds); Console.WriteLine("Renew on call time: {0}:{1}",

itfLease.RenewOnCallTime.Minutes,

itfLease.RenewOnCallTime.Seconds);

Console.WriteLine();

}

}

Now that we haveC#thisandhelperthe .typeNETinPlatform,place, assumeSecondLeaseInfoEdition .LeaseStats() is called within the GetJBCByIndex

and GetAllAutos() methods of the CarProvider type. Once we recompileISBN:1590590554the server and client assemblies (agai by Andrew Troelsen

simply to ensure VS .NET copies the latest and greatest version of the CarGeneralAsm.dll to the client and

Apress © 2003 (1200 pages)

server application directories), run the application once again. Your server's console window will now look

This comprehensive text starts with a brief overview of the something like soC#(Figurelanguage12-14and). then quickly moves to key technical and

architectural issues for .NET developers.

Table

C# and

Part

Chapter

Chapter

Part

Chapter

Chapter

Chapter

Chapter

Chapter

Chapter 8 - Advanced C# Type Construction Techniques

Figure 12-14: The default lease information for CarProvider

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

As you can see, by default, a type's initial lease time is 5 minutes. If and when a method invocation is made on Chapterthe object10 -afterProceitsses,activation,AppDomains,the RenewOnCallTimeContexts, and Threadsproperty represents the minimum value the

ChaptCurrentLeaseTimer 11 - Type Reflection,is incrementedLate Binding,by, upandto theAttributeInitialLeaseTime-B sed Programming.

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Altering the Default Lease Characteristics

Chapter 13 - Building a Better Window (Introducing Windows Forms)

ChapterObviously14 -theA Bdefaulttter Paintinglease characteristicsFr mework (GDI+)of a CAO/ WKO-singleton type may not be appropriate for each and

Chapterevery CAO15 - orProgrammiWKO-singletonwith remoteWindowsobjectForms. IfControlsyou wish to alter these default settings, you have two approache

Chapter 16 - The System.IO Namespace

As you would guess, you are able to adjust the default lease settings using a *.config file.

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

You are also able to programmatically alter the settings of a type's default lease by overriding members of

Chapter 18 - ASP.NET Web Pages and Web Controls the MarshalByRefObject base class.

Chapter 19 - ASP.NET Web Applications

ChaptWhilereach20 - ofXMLtheseW boptionsServiceswill indeed alter the default lease settings, there is a key difference. When you mak Indexuse of a server side *.config file, the lease settings affect all objects hosted by the server process! In contrast,

when you override select members of the MarshalByRefObject type, you are able to change lease settings on a

List of Figures

object-by-object basis.

List of Tables

To illustrate changing the default lease settings via a remoting *.config file, assume you have updated the serve side XML data with the following additional <lifetime> element:

<configuration>

<system.runtime.remoting>

<application>

<lifetime leaseTime = "15M" renewOnCallTime = "5M"/>

<service>

<activated type = "CarGeneralAsm.CarProvider, CarGeneralAsm"

</service>

<channels>

<channel ref="http" port="32469" />

</channels>

</application>

</system.runtime.remoting>

C# and the .NET Platform, Second Edition

 

</configuration>

ISBN:1590590554

by Andrew Troelsen

Apress © 2003 (1200 pages)

 

Notice how the leaseTimeThis comprehensiveand renewOnCallTimetext starts withpropertiesa brief overviewhave beenof themarked with the M suffix, which you might guess standsC#forlanguagethe numberand thenof minutesquickly movto sets forto keachy technicallease-centricand unit of time. If you wish, your

architectural issues for .NET developers.

<lifetime> element may also suffix the numerical values with MS (milliseconds), S (seconds), H (hours), or even D (days). Figure 12-15 shows the result of the updated *.config file:

Table of Contents

C# and

Part

Chapter

Chapter

Part

Chapter

Chapter

Chapter

Chapter

Chapter

Chapter

Part

Figure 12-15: Altering lease timing via a server-side *.config file

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Now recall that when you update the server's *.config file you have effectively changed the leasing characteristi

Part Four - Leveraging the .NET Libraries

for each CAO/WKO-singleton object hosted by the server. As an alternative, you may choose to

Chapter 12 - Object Serialization and the .NET Remoting Layer

programmatically override the InitializeLifetime() method in a specific remote type. Thus, assume you have not

Chapter 13 - Building a Better Window (Introducing Windows Forms)

updated the server's configuration file, but rather updated the CarProviderType as follows:

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls public class CarProvider : MarshalByRefObject

Chapter 16 - The System.IO Namespace

{

Chapter 17 - Data Access with ADO.NET

public override object InitializeLifetimeService()

Part Five{- Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

 

// Obtain the current lease info.

Chapter 19 - ASP.NET Web Applications

 

ILease itfLeaseInfo =

Chapter 20 - XML Web(ILease)Services base.InitializeLifetimeService();

Index

// Adjust settings.

List of Figures

itfLeaseInfo.InitialLeaseTime = TimeSpan.FromMinutes(50);

List of Tables

itfLeaseInfo.RenewOnCallTime = TimeSpan.FromMinutes(10);

}

return itfLeaseInfo;

 

...

 

}

 

Here, the CarProvider has altered its InitialLeaseTime value to 50 minutes and its RenewOnCallTime value to 1 Again, the benefit of overriding InitializeLifetimeServices() is the fact that you can configure each remote type individually. Finally, on an odd note, if you wish to disable lease-based lifetime for a given CAO/WKO-singleton object type, you may override InitializeLifetimeServices() and simply return null. If you do so, you have basically configured an MBR type that will never die as long as the hosting server application is alive and kicking.

Server-Side Lease Adjustment

As you have just seen, when an MBR type overrides InitializeLifetimeServices(), it is able to change its default

Part Three - Programming with .NET Assemblies

leasing behavior at the time of activation. However, for the sake of argument, what if a remote type desires to

C# and the .NET Platform, Second Edition

 

change its current lease after its activation cycle? For example, assume the CarProvider has a new method

by Andrew Troelsen

ISBN:1590590554

whose implementation requires a lengthy operation (such as connecting to a remote database and reading a

Apress © 2003 (1200 pages)

large set of records). Before beginning the task, you may programmatically adjust your lease such that if you

This comprehensive text starts with a brief overviewTof the

have less than 1 minute, you renew the lease time to 10 minutes. do so, you can make use of the inherited

C# language and then quickly moves to key technical and

MarshalByRefObject.GetLifetimeService() and ILease.Renew() methods as follows: architectural issues for .NET developers.

// Server-side lease adjustment.

Table// Assumeof Contenthis new method of the CarProvider type.

public void DoLengthyOperation()

C# and the .NET Platform, Second Edition

{

Introduction

ILease itfLeaseInfo = (ILease)this.GetLifetimeService();

Part One - Introducing C# and the .NET Platform

if(itfLeaseInfo.CurrentLeaseTime.TotalMinutes < 1.0)

Chapter 1 - The Philosophy of .NET

itfLeaseInfo.Renew(TimeSpan.FromMinutes(10));

Chapter 2 - Building C# Applications

// Do task...

Part Two - The C# Programming Language

}

Chapter 3 - C# Language Fundamentals

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

ChaptClientr 6 --SideInterfacesLeasend CollectionsAdjustment

Chapter 7 - Callback Interfaces, Delegates, and Events

On an additional ILease-related note, it is possible for the client's application domain to adjust the current lease

Chapter 8 - Advanced C# Type Construction Techniques

properties for a CAO/WKO-singleton type it is communicating with across the wire. To do so, the client makes

use of the static RemotingServices.GetLifetimeService() method. As a parameter to this member, the client

Chapter 9 - Understanding .NET Assemblies

passes in the reference to the remote type as follows:

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

// Client-side lease adjustment.

Part Four - Leveraging the .NET Libraries

CarProvider cp = new CarProvider(cars);

Chapter 12 - Object Serialization and the .NET Remoting Layer

ILease itfLeaseInfo = (ILease)RemotingServices.GetLifetimeService(cp);

Chapter 13 - Building a Better Window (Introducing Windows Forms) if(itfLeaseInfo.CurrentLeaseTime.TotalMinutes < 10.0)

Chapter 14 - A Better Painting Framework (GDI+) itfLeaseInfo.Renew(TimeSpan.FromMinutes(1000));

Chapter 15 - Programming with Windows Forms Controls Chapter 16 - The System.IO Namespace

ChapterThis approach17 - DatacanAccessbe helpfulwith ADOif the.NETclient's application domain is about to enter a lengthy process on the same

PartthreadFiveof- WebexecutionApplicationsthat is usingand XMLtheWebremoteS rvictypes. For example, if a single threaded application is about to print

Chaptera 100-page18 - ASPdocument,.NET WebthePageschancesand Webare quiteControlsgood that a remote CAO/WKO-singleton type may time out durin

Chapterthe process19 - .ASPThe.NETotherWeb(moreApplicationselegant) solution, of course, is to spawn a secondary thread of execution, but I thi

Chapteryou get20the- generalXML WebideaServices.

Index

List of Figures

List of Tables

Chapter 7 - Callback Interfaces, Delegates, and Events
Chapter 6 - Interfaces and Collections

Server-SideC#(andd theClient.NET Platform,-Side)SecondLeaseEditionSponsorship

by Andrew Troelsen

ISBN:1590590554

The final topic regarding the lease-based lifetime of a CAO/WKO-singleton object type considered here is

Apress © 2003 (1200 pages)

the notion of lease sponsorship. As you have just seen, every CAO/WKO-singleton entity has a default

This comprehensive text starts with a brief overview of the

lease, which mayC#belalterednguageinanda numberthen quicklyof waysmoveson bothto keythetechnicalserver sideand as well as the client side. Now, regardless of thearchitecturaltype's leaseissuesconfiguration,for .NET eventuallydevelopers.an MBR object times will be up. At this point, the runtime will garbage-collect the entity...well almost.

TableTheoftruthContentsof the matter is that before an expired type is truly marked for garbage collection, the runtime will C#checkand theto see.NETif thePlatform,MBR objectSecondinEditionquestion has any registered lease sponsors. Simply put, a sponsor is a

type that implements the ISponsor interface, which is defined as follows:

Introduction

Part One - Introducing C# and the .NET Platform

Chapterpublic1 interface- The PhilosophySystemof .NET.Runtime.Remoting.Lifetime.ISponsor

Chapter{ 2 - Building C# Applications

Part TwoTimeSpan- The C# ProgrammingRenewal(ILeaseLanguagelease);

Chapter}

3

- C# Language Fundamentals

Chapter 4

- Object-Oriented Programming with C#

Chapter 5

- Exceptions and Object Lifetime

If the runtime detects that an MBR object has a sponsor, it will not garbage-collect the type, but rather call the Renewal() method of the sponsor object to (once again) add time to the current lease. On the other

hand, if the MBR has no sponsor, the object's time is truly up.

Chapter 8 - Advanced C# Type Construction Techniques

PartAssumingThree -thatProgrammingyou have createdwith .NETa Ascustomembliesclass that implements ISponsor, and thus implements ChaptRenewal()r 9 -toUnderstandingreturn specific.NETunitAssembliof times(via the TimeSpan type), the next question is how exactly to

Chapterassociate10 the- Processes,type to aAppDomains,given remoteCobjecnt xt.s,Again,and Threadsthis operation may be performed by either the server's

Chaapplicationter 11 -domainType Reflection,or the client'sLate Binding,applicationand domainAttribute.-Based Programming

Part Four - Leveraging the .NET Libraries

To do so, the interested party obtains an ILease reference (via the inherited GetLifetimeService() method

Chapter 12 - Object Serialization and the .NET Remoting Layer

on the server or using the static RemotingServices.GetLifetimeService() method on the client) and calls

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Register():

Chapter 14 - A Better Painting Framework (GDI+) Chapter 15 - Programming with Windows Forms Controls

// Server-side sponsor registration.

Chapter 16 - The System.IO Namespace

CarSponsor mySponsor = new CarSponsor();

Chapter 17 - Data Access with ADO.NET

ILease itfLeaseInfo = (ILease)this.GetLifetimeService();

Part Five - Web Applications and XML Web Services

itfLeaseInfo.Register(mySponsor);

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

// Client-side sponsor registration.

Chapter 20 - XML Web Services

CarSponsor mySponsor = new CarSponsor();

Index

CarProvider cp = new CarProvider(cars);

List of Figures

ILease itfLeaseInfo = (ILease)RemotingServices.GetLifetimeService(cp);

List of Tables

itfLeaseInfo.Register(mySponsor);

In either case, if a client or server wishes to revoke sponsorship, it may do so using the ILease.Unregister() method. For example:

// Remove the sponsor for a given object.

itfLeaseInfo.Unregister(mySponsor);

Note Client-side sponsored objects, in addition to implementing ISponsor must also derive from MarshalByRefObject, given that the client must pass the sponsor to the remote application domain!

So, as you can see, the lifetime management of stateful MBR types is quite different from classic DCOM.

On the plus side, you have a ton of control regarding when a remote type is destined to meet its maker.

C# and the .NET Platform, Second Edition

 

However, as you may be able to gather, there is the chance that a remote type may be removed from

by Andrew Troelsen

ISBN:1590590554

memory without the client's knowledge. Should a client attempt to invoke members on a type that has

Apress © 2003 (1200 pages)

already been removed from memory the runtime will throw a

This comprehensive text starts with a brief overview of the

System.Runtime.Remoting.RemotingException, at which point the client may simply create a brand-new

C# language and then quickly moves to key technical and instance of the remote type or simply take an alternative course of action.

architectural issues for .NET developers.

SOURCE The CAOCarGeneralAsmLease, CAOCarProviderServerLease, and

CODE CAOCarProviderClientLease projects are located under the Chapter 12 subdirectory.

Table of Contents

C# and the .NET Platform, Second Edition

Introduction

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

Chapter 3 - C# Language Fundamentals

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

Chapter 14 - A Better Painting Framework (GDI+)
Chapter 13 - Building a Better Window (Introducing Windows Forms)

AlternativeC#Hostsand thefor.NETRemotePlatf rm, SecondObjectsEdition

by Andrew Troelsen

ISBN:1590590554

Over the course of this chapter, you have constructed numerous console-based server hosts, which provide

Apress © 2003 (1200 pages)

access to some set of remote objects. If you have a background in classic DCOM, this step may have

This comprehensive text starts with a brief overview of the

seemed a bit oddC#. Underlanguagethe worldand thenof DCOM,quickly itmoveswas notto keyunusualtechnicalto buildand a single server-side COM server that contained thearchitecturalremote objectsissuesandforwas.NETalsodevelopersin charge. of receiving incoming ORCP requests from some remote client. This single *.exe DCOM application would quietly load in the background without presenting a looming command window.

Table of Contents

C#Whenand theyou.areNETbuildingPlatform,aSecond.NET serverEditionassembly, the chances are quite good that the remote machine does

not need to display any sort of UI. Rather, all you really wish to do is build a server-side entity that opens the

Introduction

correct channel(s) and registers the remote object(s) for client-side access. Moreover, when you build a

Part One - Introducing C# and the .NET Platform

simple console host, you (or someone) is required to manually run the server-side *.exe assembly, due to

Chapter 1 - The Philosophy of .NET

the fact that the .NET Remoting will not automatically run a server-side *.exe when called by a remote

Chapter 2 - Building C# Applications

client. Given these two issues, the question then becomes: How can you build an invisible listener that loads

Part Two - The C# Programming Language

automatically (in one way or another)?

Chapter 3 - C# Language Fundamentals

Chapter 4 - Object-Oriented Programming with C#

Unlike classic DCOM, you are unable to simply pass your command windows a command line parameter

Chapter 5 - Exceptions and Object Lifetime

that instructs the process to appear invisibly in the background. Rather, .NET programmers have two major

Chapter 6 - Interfaces and Collections

choices at their disposal, when they wish to build a transparent host for various remote objects:

Chapter 7 - Callback Interfaces, Delegates, and Events

Build a .NET Windows Service application to host the remote objects

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Allow IIS to host your remote objects

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Hosting Remote Objects Using a Windows Service

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Perhaps the ideal host for remote objects is a Windows service, given that it (a) can be configured to load

Chapter 12 - Object Serialization and the .NET Remoting Layer

automatically on system start-up, (b) runs as an invisible background process, and (c) can be run under discrete user accounts. As you would expect, building a custom Windows Service using the .NET platform

is extremely simple when contrasted to the raw Win32 API. To illustrate, let's create a Windows Service

Chapter 15 - Programming with Windows Forms Controls

project (named CarWinService) that will be in charge of hosting the remote types contained within the

Chapter 16 - The System.IO Namespace

CarGeneralAsm.dll. To begin, create a new Windows Service project workspace (Figure 12-16).

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter

Chapter

Chapter

Index

List of

List of

Figure 12-16: Creating a new Windows Service project workspace

As you can see, VS .NET responds by generating a new class (named Service1 by default) which derives from System.ServiceProcess.ServiceBase. Given that Service1 is a rather nondescript name for your custom service, your first order of business is to change the values of the (Name) and ServiceName properties to CarService using the IDE's Properties window. The distinction between these two settings is that the (Name) value is used to define the name used to refer to our type in the code base, while the ServiceName property marks the name to display to Windows Service-centric configuration tools (such as

MMC, seen shortly).

C# and the .NET Platform, Second Edition

The generated classby AndrtypewdefinesTro l enthree methods of interest, twoISBN:1590590554of which (OnStart() and OnStop()) are base class overrides:Apress © 2003 (1200 pages)

This comprehensive text starts with a brief overview of the

Main(): This method is the entry point of the Windows Service process.

C# language and then quickly moves to key technical and

architectural issues for .NET developers.

OnStart(): This method is called each time the service is started.

OnStop(): This method is called when the service is stopped.

Table of Contents

C# and the .NET Platform, Second Edition

First, let's take a peek at the Main() method. Before you do, be sure you set a reference to the

Introduction

CarProviderAsm.dll and System.Remoting.dll assemblies, and specify the following additional "using"

Part One - Introducing C# and the .NET Platform

directives:

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

using System.Runtime.Remoting;

Part Two - The C# Programming Language

using System.Runtime.Remoting.Channels.Http;

Chapter 3 - C# Language Fundamentals

using System.Runtime.Remoting.Channels;

Chapter 4 - Object-Oriented Programming with C# Chapter 5 - Exceptions and Object Lifetime Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

Implementing Main()

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

The Main() method of a ServiceBase-derived type is in charge of running each service defined in the project

Chapter 9 - Understanding .NET Assemblies

by passing an array of ServiceBase types into the static Service.Run() method. Given that you have

Chapter 10 - Processes, AppDomains, Contexts, and Threads

renamed your custom service from Service1 to CarService, be sure to update the autogenerated array:

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

static void Main()

Chapter 12 - Object Serialization and the .NET Remoting Layer

{

Chapter 13 - Building a Better Window (Introducing Windows Forms)

System.ServiceProcess.ServiceBase[] ServicesToRun;

Chapter 14 - A Better Painting Framework (GDI+)

ServicesToRun = new System.ServiceProcess.ServiceBase[]

Chapter 15 - Programming with Windows Forms Controls

{ new CarService() };

Chapter 16 - The System.IO Namespace

System.ServiceProcess.ServiceBase.Run(ServicesToRun);

Chapter} 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Implementing OnStart()

Chapter 20 - XML Web Services

IndexI would guess you can already assume what sort of logic should happen when your custom service is

Listartedt of Figureson a given machine. Recall that the role of CarService is to perform the same tasks as your custom

Listconsoleof Tables-based service. Thus, if you wish to register CarService as a WKO singleton type which is available via HTTP, you could add the following code to the OnStart() method (as you would hope, you may make use of the RemotingConfiguration type to load up a server side remoting *.config file, rather than hardcoding your implementation, when hosting remote objects using a Windows Service).

using System.Diagnostics; // For the EventLog type.

...

protected override void OnStart(string[] args)

{

// Create a new HttpChannel

HttpChannel c = new HttpChannel(32469);

ChannelServices.RegisterChannel(c);

// Register as single call WKO.

RemotingConfiguration.RegisterWellKnownServiceType(

typeof(CarGeneralAsm.CarProvider),

"CarProvider.soap",

WellKnownObjectMode.SingleCall);

C# and the .NET Platform, Second Edition

// Log our successful start-up.

by Andrew Troelsen

ISBN:1590590554

EventLog.WriteEntry("CarGeneralAsm",

 

Apress © 2003 (1200 pages)

"CarWinService started successful!",

This comprehensive textInformation);starts wi h a brief overview of the

EventLogEntryType.

C# language and then quickly moves to key technical and

}

architectural issues for .NET developers.

Note that once the type has been registered, log a custom message to the Windows event log (via the

Table of Contents

System.Diagnostics.EventLog type) that informs the host machine of our successful start-up.

C# and the .NET Platform, Second Edition

Introduction

Implementing OnStop()

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Technically speaking, our CarService does not demand any sort of shutdown logic. For illustrative purposes

Chapter 2 - Building C# Applications

let's post another event to the EventLog to log the termination of your custom Windows Service:

Part Two - The C# Programming Language

Chapter 3 - C# Language Fundamentals

protected override void OnStop()

Chapter 4 - Object-Oriented Programming with C#

{

Chapter 5 - Exceptions and Object Lifetime

EventLog.WriteEntry("CarGeneralAsm",

Chapter 6 - Interfaces and Collections

"CarWinService stopped",

Chapter 7 - Callback Interfaces, Delegates, and Events

EventLogEntryType.Information);

Chapter 8 - Advanced C# Type Construction Techniques

}

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

ChapterAs you10would- Procesguess,es,youAppDomains,may chooseContexts,to makeanduseThreadsof the TcpChannel type as opposed to the HttpChannel, Chapposterthe11CarProvider- Type R flection,MBR typeLateasBinding,a CAOandobjectAttribute(rather-BasedthanProgrammingWKO), and so forth. Now that the service is Partcomplete,Four - Leveragingthe next tasktheis.NETto installLibrariesthis service on the remote machine.

Chapter 12 - Object Serialization and the .NET Remoting Layer

ChapterAdding13 - aBuildingServicea BetterInstallerWindow (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

ChapterBefore15you- canProgramminginstall yourwithserviceWindonwsaFormsgiven Controlsmachine, you need to add an additional type into your current

CarWinService project. Specifically speaking, any Windows service (written using .NET or the raw Win32

Chapter 16 - The System.IO Namespace

API) requires a number of registry entries to be made to allow the OS to interact with the service itself.

Chapter 17 - Data Access with ADO.NET

Rather than requiring us to make these entries manually, you can simply add an Installer type to a Windows

Part Five - Web Applications and XML Web Services

Service project, which will configure your ServiceBase-derived type correctly when installed onto the target

Chapter 18 - ASP.NET Web Pages and Web Controls

machine. To add an installer for the CarService, open the design-time service editor (by double-clicking the

Chapter 19 - ASP.NET Web Applications

CarService.cs file from the Solutions Explorer), and click the Add Installer link that now appears on the

Chapter 20 - XML Web Services

bottom of the Properties window (Figure 12-17).

Index

List of Figures

List of

Figure 12-17: Including an installer for the custom Windows Service

C# and the .NET Platform, Second Edition

This selection willbyaddAndrewa newTroelsencomponent that derives from theISystemBN:1590590554.Configuration.Install.Installer base class. While thereApressare numerous© 2003 (1200wayspages)to configure your installer (both programmatically and declaratively), the default settingsThisarecompreheall you needsive toextinstallt rtsyourwithCarWinServicebrief overvi w.exeof theon a given machine. Now, compile

your project. C# language and then quickly moves to key technical and architectural issues for .NET developers.

Installing the CarService

Table of Contents

To install CarService.exe on a given machine (local or remote) requires two steps:

C# and the .NET Platform, Second Edition

Introduction1. Move the compiled service assembly (and any necessary external assemblies) to the remote

Part Onemachine- Introducing(obviously)C# and. the .NET Platform

Chapter 1 - The Philosophy of .NET

2. Run the Installutil.exe command line tool, specifying your service as an argument.

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

Assuming step one is complete, open a command window, navigate to the location of the

Chapter 3 - C# Language Fundamentals

CarWinService.exe assembly, and issue the following command:

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

Installutil carwinservice.exe

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

ChaptOncerthis8 Windows- AdvancedServiceC# TypehasConstructibeen properlyn Techniquesinstalled, you are now able to start and configure it using the

PartServicesThr applet,- Programminglocated underwith .NETtheAdministrativessemblies Tools folder of your system's Control Panel. Once you Chavepterlocated9 - Understandingyour CarService.NET(FigureAssemblies12-18), click the Start link to load and run the binary.

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter

-Based Programming

Part

 

Chapter

Layer

Chapter

Windows Forms)

Chapter

 

Chapter

 

Chapter

 

Chapter

 

Part

 

Chapter

 

Chapter

 

Chapter

 

Index

Figure 12-18: The Windows Services Applet

List of Figures

List of Tables

Once the service is started, you are able to run your client application as before.

Now that you have seen how to host your remote objects using a custom Windows Service, let's see how to host remote types using IIS.

SOURCE

The CarWinService project is located under the Chapter 12 subdirectory.

CODE

Hosting Remote Objects Using IIS

Hosting a remote assembly under the care of IIS is even simpler than building a Windows Service, given that IIS is already preprogrammed to allow incoming HTTP requests via port 80. Now, given the fact that IIS is a Web server, it should stand to reason that IIS is only able to host remote objects using the HttpChannel type (unlike a Windows Service that can also leverage the TcpChannel type). Assuming this is not perceived as a limitation, follow the steps below to leverage the remoting support of IIS:

1. On your hard drive, create a new folder to hold your CarGeneralAsm.dll. Within this folder, create a

Chapter 1 - The Philosophy of .NET
Part One - Introducing C# and the .NET Platform

subdirectory named \Bin. Now, copy the CarGeneralAsm.dll to this subdirectory (for example:

C# and the .NET Platform, Second Edition

C:\IISHostCarService\Bin). Do be aware that you are also able to install your general assembly into

by Andrew Troelsen ISBN:1590590554

the GAC of the web-server machine as an alternative to placing a copy under the \Bin folder.

Apress © 2003 (1200 pages)

2. Open the InternetThis comprehensiveInformationtextServicesstartsappletwith a onbrieftheoverviewhost machineof the (located under the Administrative Tools folderC#underlanguageyourandsystem'sthen quicklyControlmovesPanel)to.key technical and

architectural issues for .NET developers.

3. Right-click the "Default Web Site" node and select "New | Virtual Directory".

Table4of. Createontentsa virtual directory that maps to the root folder you just created (C:\IISCarService). The

remaining default settings presented by the New Virtual Directory Wizard are fine.

C# and the .NET Platform, Seco d Edition

Introduction

5. Finally, create a new configuration file named "web.config" (and only web.config) to control how this virtual directory should register the remote type (see the following). Make sure this file is saved under

the root folder (in this example, C:\IISCarService).

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

<configuration>

Chapter 3 - C# Language Fundamentals

<system.runtime.remoting>

Chapter 4 - Object-Oriented Programming with C#

<application>

Chapter 5 - Exceptions and Object Lifetime

<service>

Chapter 6 - Interfaces and Collections

<wellknown mode="Singleton"

Chapter 7 - Callback Interfaces, Delegates, and Events

type="CarGeneralAsm.CarProvider, CarGeneralAsm"

Chapter 8 - Advanced C# Type Construction Techniques

objectUri="carprovider.soap" />

Part Three - Programming with .NET Assemblies

</service>

Chapter 9 - Understanding .NET Assemblies

<channels>

Chapter 10 - Processes, AppDomains, Contexts, and Threads

<channel ref="http"/>

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

</channels>

Part Four - Leveraging</application>the .NET Libraries

Chapter 12 - Object</systemSerialization.runtimeand the.remoting>.NET Remoting Layer

Chapter </configuration>13 - Building Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Now that your CarGeneralAsm.dll has been configured to be reachable via HTTP requests under IIS, you

Chapter 16 - The System.IO Namespace

can update your client-side *config file as follows (using the name of your IIS host, of course):

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

<configuration>

Chapter 18 - ASP.NET Web Pages and Web Controls

<system.runtime.remoting>

Chapter 19 - ASP.NET Web Applications

<application>

Chapter 20 - XML Web Services

<client displayName = "CarClient">

Index

<wellknown

List of Figures

type="CarGeneralAsm.CarProvider, CarGeneralAsm"

List of Tables

url="http://NameTheRemoteIISHost/IISCarHost/carprovider.soap"/>

</client>

<channels>

<channel ref="http"/>

</channels>

</application>

</system.runtime.remoting>

</configuration>

Cool! At this point, you are able to run your client application as before.

AsynchronousC# andRemotingthe .NET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

Next, let's examine how to invoke members of a remote type asynchronously. In Chapter 7 you were first

Apress © 2003 (1200 pages)

introduced to the topic of asynchronous method invocations, given the support provided by the

This comprehensive text starts with a brief overview of the

System.MulticastDelageteC# languagetypeand. Asthenyouquickwouldy movexpect,s toif keya clientt chnicalassemblyand wishes to call a remote object asynchronously, thearchitecturalfirst stepissuesis to definefor .NETa customdevelopersdelegate. to represent the remote method in question. At this point, the caller can make use of any of the techniques seen in Chapter 7 to invoke and receive the method return value.

Table of Contents

C#Byandwaytheof .aNETsimplePlatform,illustration,SecondcreateEditiona new console application (AsyncWKOCarProviderClient) and set a

reference to the first iteration of the CarGeneralAsm.dll assembly. Now, update the Main() method to look

Introduction

like this:

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Chapterclass2AsyncCarClient- Building C# Applications

Part{ Two - The C# Programming Language

Chapter //3 -TheC# LanguadelegateFundamenfor theals GetAllAutos() method.

internal delegate ArrayList GetAllAutosDelegate();

Chapter 4 - Object-Oriented Programming wi h C#

static void Main(string[] args)

Chapter 5 - Exceptions and Object Lifetime

{

Chapter 6 - Interfaces and Collections

Console.WriteLine("Client started! Hit enter to end");

Chapter 7 - Callback Interfaces, Delegates, and Events

RemotingConfiguration.Configure

Chapter 8 - Advanced C# Type Construction Techniques

("AsyncWKOCarProviderClient.exe.config");

Part Three - Programming with .NET Assemblies

// Make the car provider.

Chapter 9 - Understanding .NET Assemblies

CarProvider cp = new CarProvider();

Chapter 10 - Processes, AppDomains, Contexts, and Threads

// Make the delegate.

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

GetAllAutosDelegate getCarsDel =

Part Four - Leveraging the .NET Libraries

new GetAllAutosDelegate(cp.GetAllAutos);

Chapter 12 - Object Serialization and the .NET Remoting Layer

// Call GetAllAutos() asynchronously.

Chapter 13 - Building a Better Window (Introducing Windows Forms)

IAsyncResult ar = getCarsDel.BeginInvoke(null, null);

Chapter 14 - A Better Painting Framework (GDI+)

// Simulate client side activity.

Chapter 15 - Programming with Windows Forms Controls while(!ar.IsCompleted)

Chapter 16 - The System.IO Namespace

{ Console.WriteLine("Client working..."); }

Chapter 17 - Data// AccessAll done!with ADOGet.NETreturn value from delegate.

Part Five - WebArrayListApplicat ons andallJBCsXML Web= ServicesgetCarsDel.EndInvoke(ar);

Chapter 18 - ASP//.NETUseWeballPagescarsand inWebArrayListControls .

Chapter 19 - ASPforeach(JamesBondCar.NETWeb Applicati j in allJBCs)

UseCar(j);

Chapter 20 - XML Web Services

Index Console.ReadLine();

}

List of Figures

}

List of Tables

Notice how the client application first declares a delegate that matches the signature of the GetAllAutos() method of the remote CarProvider type. When the delegate is created, you pass in the name of the method to call (GetAllAutos), as always. Next, you trigger the BeginInvoke() method, cache the resulting IAsyncResult interface, and simulate some work on the client side (recall that the IAsyncResult.IsCompleted property allows you to monitor if the associated method has completed processing). Finally, once the client's work has completed, you obtain the ArrayList returned from the CarProvider.GetAllAutos() method by invoking the EndInvoke() member, and pass each JamesBondCar into a static helper function named UseCar():

public static void UseCar(JamesBondCar j)

{

Console.WriteLine("Can car fly? {0}", j.isFlightWorthy);

Console.WriteLine("Can car swim? {0}", j.isSeaWorthy);

}

C# and the .NET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

Again, the beautyApressof the©.NET2003 (1200delegatep s)type is the fact that the logic used to invoke remote methods

asynchronously isThisidenticalcomprehensiveto the processtext startsof localwithmethoda brief overviewinvocationsof .the

C# language and then quickly moves to key technical and

SOURCE architecturalThe AsyncWKOCarProviderClientissues for .NET develop rs.project is located under the Chapter 12

CODE subdirectory.

Table of Contents

C# and the .NET Platform, Second Edition

Introduction

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

Chapter 3 - C# Language Fundamentals

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

The Role ofC#theand[OneWayAttribute]the .NET Platform, Second EditionType

by Andrew Troelsen

ISBN:1590590554

To wrap things up, let's consider a .NET attribute that allows the remote client to automatically invoke a

Apress © 2003 (1200 pages)

method asynchronously, without requiring the use of formal delegates. Imagine that your CarProvider has

This comprehensive text starts with a brief overview of the

a new method namedC# languageAddCar(),andwhicht en quicklytakes amovesJamesBondCarto key technicalinputandparameter and returns nothing. The key point is that itarchitecturalreturns nothingissues. Asforyou.NETmightdevelopersassume. given the name of the System.Runtime.Remoting.Messaging.OneWayAttribute class, the .NET Remoting layer passes the call to the remote one-way method but does not bother to set up the infrastructure used to return a given value

Table of Contents

(hence, the name one-way). Here is the update:

C# and the .NET Platform, Second Edition

Introduction

// Home of the [OneWay] attribute.

Part One - Introducing C# and the .NET Platform

using System.Runtime.Remoting.Messaging;

Chapter 1 - The Philosophy of .NET

namespace CarGeneralAsm

Chapter 2 - Building C# Applications

{

Part Two - The C# Programming Language

public class CarProvider : MarshalByRefObject

Chapter 3 - C# Language Fundamentals

{

Chapter 4 - Object-Oriented Programming with C#

private ArrayList theJBCars = new ArrayList();

Chapter... 5 - Exceptions and Object Lifetime

Chapter 6 - Interfaces// TheandclientCollectionscan 'fire and forget' when calling this method.

Chapter 7 - Callback[OneWay]Interfaces, Delegates, and Events

public void AddCar(JamesBondCar newJBC)

Chapter 8 - Advanced C# Type Construction T chniques

{ theJBCars.Add(newJBC);}

Part Three - Programming with .NET Assemblies

}

Chapter 9 - Understanding .NET Assemblies

}

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Callers would invoke this method directly as always:

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

// Make the car provider.

Chapter 14 - A Better Painting Framework (GDI+)

CarProvider cp = new CarProvider();

Chapter 15 - Programming with Windows Forms Controls

// Add a new car.

Chapter 16 - The System.IO Namespace

cp.AddCar(new JamesBondCar("Zippy", 200, false, false));

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

ChapterFrom the18 client's- ASP.NETpointWebof view,PagestheandcallWebtoControlsAddCar() is completely asynchronous, as the CLR will ensure

Chapterthat a background19 - ASP.NETthreadWeb Applicationsis used to remotely trigger the method. Given that AddCar() has been decorated

Chapterwith the20[OneWay]- XML Webattribute,Servicesthe client is unable to obtain any return value from the call. Because AddCar() Indexreturns void, this is not an issue. In addition to this restriction, also be aware that if you have a [OneWay]

method that defines output or reference parameters (via the "out" or "ref" keyword), the caller will not be

List of Figures

able to obtain the callee's modification(s). Furthermore, if the [OneWay] method happens to throw an

List of Tables

exception (of any type), the caller is completely oblivious to this fact. In a nutshell, remote objects can mark select methods as [OneWay] to allow the caller to employ a fire-and-forget mentality.

Final ThoughtsC# and...the .NET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

That wraps up our investigation of the .NET Remoting layer. I'd bet that you still have many questions

Apress © 2003 (1200 pages)

bouncing around at this point (which, sadly, I just don't have the physical space to cover in this text). For

This comprehensive text starts with a brief overview of the example: C# language and then quickly moves to key technical and

architectural issues for .NET developers.

How can I prevent the client-side assembly from referencing general assemblies containing CIL to protect proprietary code?

Table of Contents

How can I incorporate message queuing (MSMQ) in a .NET application?

C# and the .NET Platform, Second Edition

Introduction

How can I leverage component services (aka COM+ services) in a .NET application?

Part One - Introducing C# and the .NET Platform

ChapterHow1 can- TheI augmentPhilosophy(orofreplace).NET the default .NET Remoting layer?

Chapter 2 - Building C# Applications

What about security issues?

Part Two - The C# Programming Language

Chapter 3 - C# Language Fundamentals

If you are interested in learning more about the .NET Remoting layer (and related topics such as MSMQ a

Chapter 4 - Object-Oriented Programming with C#

la .NET), check out Distributed .NET Programming in C# (Barnaby, Apress 2002). If you are interested in

Chapter 5 - Exceptions and Object Lifetime

learning the ins-and-outs of building secure .NET applications (local, remote, or otherwise) pick up a copy

Chapter 6 - Interfaces and Collections

of.NET Security (Bock et al., Apress 2002). And as a friendly reminder, if you need to dive deep into the

Chapter 7 - Callback Interfdefaultces, Delegates, and Events

topic of bypassing the remoting layer, check out Advanced .NET Remoting (Rammer, Apress

Chapter2002). 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

Соседние файлы в предмете Программирование