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

Testing the Remoting Application

C# and the .NET Platform, Sec d Edition

by Andrew Troelsen

ISBN:1590590554

To test your application,Apress ©begin2003 (1200by launchingpages)

the server application, which will open an HTTP channel and

register your remote object for access. Next, launch an instance of the client application. If all is well, your

This comprehensive text starts with a brief overview of the

server window shouldC# languageappearandas followsthen quickly(Figuremoves12-8to) whilekey technicalthe clientandapplication presents what you see in

Figure 12-9. architectural issues for .NET developers.

Table

C# and

Part

Chapter

Figure 12-8: The server's output

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

Chapter

Chapter

C#

Chapter

Chapter

Figure 12-9: The client's output

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

UnderstandingC# andthet .ChannelServicesNET Platform, Second EditionType

by Andrew Troelsen

ISBN:1590590554

As you have seen, when a server application wishes to advertise the existence of a remote type, it makes

Apress © 2003 (1200 pages)

use of the System.Runtime.Remoting.Channels.ChannelServices type. ChannelServices provides a small

This comprehensive text starts with a brief overview of the

set of static methodsC# languthat aidgeinandthethenprocessquicklyofmovesremotingto keychanneltechnicalregistration,and resolution, and URL discovery.Table 12architectural-7 documentsissuestheformembers.NET developersin question. .

Table 12-7: Select Members of the ChannelServices Type

Table of Contents

 

Meaning in Life

 

C#Memberand the .NETof Platform, Second Edition

 

 

IntroductionChannelServices

 

 

 

 

 

 

 

 

Part One - Introducing C# and the .NET

 

Platform

 

 

RegisteredChannels

 

This property gets or sets a list of currently registered

 

Chapter 1

- The Philosophy of .NET

 

channels, each of which is represented by the IChannel

 

Chapter 2

- Building C# Applications

 

 

 

interface.

 

 

 

 

 

 

Part Two - The C# Programming Language

 

 

ChapterAsyncDispatchMessage()3 - C# Language Fundamentals

 

Asynchronously dispatches the given message to the

 

Chapter 4

- Object-Oriented Programming

 

server-side chain(s) based on the URI embedded in the

 

 

with C#

 

 

 

 

 

message.

 

 

Chapter 5 - Exceptions and Object Lifetime

 

 

 

Chapter 6 - Interfaces and Collections

 

Creates a channel sink chain for the specified channel.

 

 

CreateServerChannelSinkChain()

 

 

 

 

 

 

 

 

Chapter 7 - Callback Interfaces, Delegates, and Events

 

 

DispatchMessage()

 

Dispatches incoming remote calls.

 

 

Chapter 8

- Advanced C# Type Construction Techniques

 

 

 

 

 

 

 

PartGetChannel()Three - Programming with .NET AssembliesReturns a registered channel with the specified name.

Chapter 9

- Understanding .NET Assemblies

GetChannelSinkProperties()

Returns an IDictionary of properties for a given proxy.

Chapter 10

- Processes, AppDomains, Contexts, and Threads

ChapterGetUrlsForObject()11 - Type Reflection, Late Binding,Returnsand Attributean array-Basedof allProgrammingthe URLs that can be used to reach

Part Four - Leveraging the .NET Libraries the specified object.

 

Chapter 12 - Object Serialization and the

 

 

.NET Remoting Layer

 

 

 

RegisterChannel()

 

 

Registers a channel with the channel services.

 

 

 

Chapter 13 - Building a Better Window

 

 

(Introducing Windows Forms)

 

 

 

 

 

 

SyncDispatchMessage()

 

 

Synchronously dispatches the incoming message to the

 

 

 

Chapter 14 - A Better Painting Framework

 

 

(GDI+)

 

 

 

Chapter 15 - Programming with Windows

 

 

Foserverms -Controlsside chain(s) based on the URI embedded in the

 

 

 

Chapter 16

- The System.IO Namespace

 

 

message.

 

 

 

 

 

 

 

 

 

 

Chapter 17

- Data Access with ADO.NET

 

 

Unregisters a particular channel from the registered

 

 

 

UnregisterChannel()

 

 

 

 

Part Five - Web Applications and XML Web Services

 

 

 

 

 

 

 

channels list.

 

 

 

Chapter 18

- ASP.NET Web Pages and Web Controls

 

 

Chapter 19 - ASP.NET Web Applications

In addition to the aptly named RegisterChannel() and UnregisterChannel() methods, ChannelServices

Chapter 20 - XML Web Services

defines the RegisteredChannels property. This member returns an array of IChannel interfaces, that each

Index

represent a handle to each channel registered in a given application domain. The definition of the

List of Figures

IChannel interface is quite straightforward:

List of Tables

public interface IChannel

{

string ChannelName { get; } int ChannelPriority { get; }

string Parse(string url, ref String objectURI);

}

As you can see, each channel is given a friendly string name as well as a priority level. To illustrate, if you were to update the SimpleRemoteObjectClient application with the following logic:

// List all registered channels.

IChannel[] channelObjs = ChannelServices.RegisteredChannels;

foreach(IChannel i in channelObjs)

{

Console.WriteLine("Channel name: {0}", i.ChannelName);

C# and the .NET Platform, Second Edition

Console.WriteLine("Channel Priority: {0}", i.ChannelPriority);

}

by Andrew Troelsen

ISBN:1590590554

Apress © 2003 (1200 pages)

 

 

 

This comprehensive text starts with a brief overview of the

You would find theC#clientanguageside consoleand thennowquicklylooksmoveslike toFigurekey technical12-10. and

architectural issues for .NET developers.

Table

C# and

Part

Chapter 1 - The Philosophy of .NET

Figure 12-10: Enumerating client-side channels

Chapter 2 - Building C# Applications

PartTheTwomajority- TheofC#theProgrammingremaining methodsLanguageof ChannelServices are used to interact with custom sink types,

Chapterwhich may3 -beC#plugLanguageed intoFundamentalsthe .NET Remoting layer.

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

Part Four - Leveraging the .NET Libraries
GetRegisteredActivatedServiceTypes()
Part Three - Programming with .NET Assemblies

UnderstandingC# andthet .RemotingConfigurationNET Platform, Seco d Edition Type

by Andrew Troelsen

ISBN:1590590554

Another key remoting-centric type is RemotingConfiguration, which as the name suggests, is used to

Apress © 2003 (1200 pages)

configure various aspects of a remoting application. Currently, you have seen this type in use on the server

This comprehensive text starts with a brief overview of the

side (via the call toC#thelanguageRegisterWellKnownServiceType()and then quickly moves to keymethod)technical. Tablend 12-8 lists additional static

members of interest,architecturalsome ofissueswhichforyou.NETseedevelopersin action over. the remainder of this chapter:

Table 12-8: Members of the RemotingConfiguration Type

Table of Contents

 

Meaning in Life

C#Memberand the .NETof Platform, Second Edition

 

IntroductionRemotingConfiguration

 

 

 

 

 

 

Part One - Introducing C# and the .NET Platform

 

Gets the ID of the currently executing application

 

ApplicationId

 

 

Chapter 1 - The Philosophy of .NET

 

 

 

 

 

 

ChapterApplicationName2 - Building C# Applications

 

Gets or sets the name of a remoting application

 

 

 

 

Part Two - The C# Programming Language

 

Gets the ID of the currently executing process

 

ProcessId

 

 

Chapter 3

- C# Language Fundamentals

 

 

 

 

 

 

ChapterConfigure()4 - Object-Oriented Programming with

 

C#Reads the configuration file and configures the

 

Chapter 5

- Exceptions and Object Lifetime

 

remoting infrastructure

 

 

 

 

Chapter 6

- Interfaces and Collections

 

Retrieves an array of object types registered on the

 

GetRegisteredActivatedClientTypes()

 

 

Chapter 7

- Callback Interfaces, Delegates, and

 

Events

 

 

 

 

client as types that will be activated remotely

Chapter 8 - Advanced C# Type Construction Techniques

Retrieves an array of object types registered on the

service end that can be activated on request from a

Chapter 9 - Understanding .NET Assemblies

client

Chapter 10 - Processes, AppDomains, Contexts, and Threads

ChapterGetRegisteredWellKnownClientTypes()11 - R flection, Late Binding, and AttributeRetrieves-Basedan arrayProgrammingof object types registered on the client end as well-known types

 

 

 

 

 

 

 

Chapter 12 - Object Serialization and the .NET

 

Remoting Layer

 

 

GetRegisteredWellKnownServiceTypes()

 

 

Retrieves an array of object types registered on the

 

 

Chapter 13 - Building a Better Window (Introducing

 

 

Windows Forms)

 

 

Chapter 14 - A Better Painting Framework (GDI+)

 

 

service end as well-known types

 

 

 

 

 

 

 

ChapterIsActivationAllowed()15 - Programming with Windows Forms

 

 

ControlsReturns a Boolean value indicating whether the

 

 

Chapter 16 - The System.IO Namespace

 

 

specified Type is allowed to be client activated

 

 

 

 

 

Chapter 17 - Data Access with ADO.NET

 

 

Checks whether the specified object type is

 

 

IsRemotelyActivatedClientType()

 

 

 

Part Five - Web Applications and XML Web Services

 

 

 

 

 

registered as a remotely activated client type

 

 

Chapter 18 - ASP.NET Web Pages and Web Controls

 

 

 

 

ChapterIsWellKnownClientType()19 - ASP.NET Web Applications

Checks whether the specified object type is

 

 

Chapter 20 - XML Web Services

 

registered as a well-known client type

 

 

 

 

 

 

Index

 

 

Registers an object Type on the client end as a type

 

 

RegisterActivatedClientType()

 

 

 

List of Figures

 

 

that can be activated on the server

 

 

 

 

 

 

 

List of Tables

 

 

 

 

 

Registers an object Type on the service end as one

 

 

RegisterActivatedServiceType()

 

 

 

 

 

 

 

that can be activated on request from a client

 

 

 

 

 

 

RegisterWellKnownClientType()

 

 

Registers an object Type on the client end as a well-

 

 

 

 

 

known type (single call or singleton)

 

 

 

 

 

 

RegisterWellKnownServiceType()

 

 

Registers an object Type on the service end as a

 

 

 

 

 

well-known type (single call or singleton)

 

Recall that the .NET Remoting layer distinguishes between two types of MBR objects: WKO (aka server activated) and CAO (aka client activated). Furthermore, WKO types can be configured to make use of singleton or single call activations. Using the functionality of the RemotingConfiguration type, you are able to dynamically obtain such information at runtime. For example, if you update the Main() method of your SimpleRemoteObjectServer application with the following:

static void Main(string[] args)

{

C# and the .NET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

...

Apress © 2003 (1200 pages)

 

 

// Set a friendly name for this server app.

 

This comprehensive text starts w th a brief overview of the

 

RemotingConfiguration.ApplicationName

= "First server app!";

C# language and then quickly moves to key technical and

Console.WriteLine("App Name: {0}", architectural issues for .NET developers.

RemotingConfiguration.ApplicationName);

// Get an array of WellKnownServiceTypeEntry types

// that represent all the registered WKOs.

Table of Contents

WellKnownServiceTypeEntry[] WKOs =

C# and the .NET Platform, Second Edition

RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

Introduction

// Now print their statistics.

Part One - Introducing C# and the .NET Platform

foreach(WellKnownServiceTypeEntry wko in WKOs)

Chapter 1 - The Philosophy of .NET

{

Chapter 2 - Building C# Applications

Console.WriteLine("Asm name containing WKO: {0}", wko.AssemblyName);

Part Two - The C# Programming Language

Console.WriteLine("URL to WKO: {0}", wko.ObjectUri);

Chapter 3 - C# Language Fundamentals

Console.WriteLine("Type of WKO: {0}", wko.ObjectType);

Chapter 4 - Object-Oriented Programming with C#

Console.WriteLine("Mode of WKO: {0}", wko.Mode);

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

you will find a list of all WKO types registered by this server application domain. As you iterate over the array

Part Three - Programming with .NET Assemblies

of WellKnownServiceTypeEntry types, you are able to print out various points of interest regarding each

Chapter 9 - Understanding .NET Assemblies

WKO. Given that our server's application only registered a single type

Chapter 10 - Processes, AppDomains, Contexts, and Threads

(SimpleRemotingAsm.RemoteMessageObject), we find the following output (Figure 12-11).

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

Part Four - Leveraging the .NET Libraries

 

Chapter

Layer

Chapter

Windows Forms)

Chapter

 

Chapter

Controls

Chapter

 

Chapter

 

Part

 

ChapterFigure18 - 12ASP-11:.NETServerWeb -Pagsidesstatisticsand Web Controls

Chapter 19 - ASP.NET Web Applications

The other major method of the RemotingConfiguration type is Configure(). As you see in just a bit, this static

Chapter 20 - XML Web Services

member allows the clientand server-side application domains to make use of remoting configuration files.

Index

List of Figures

List of Tables

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