.NET Remoting Module Subtitle Building distributed applications and - - PowerPoint PPT Presentation

net remoting
SMART_READER_LITE
LIVE PREVIEW

.NET Remoting Module Subtitle Building distributed applications and - - PowerPoint PPT Presentation

.NET Remoting Module Subtitle Building distributed applications and implementing attribute-driven behaviors with Microsoft .NET Contents Section 1: Overview Section 2: Remoting Architecture Section 3: Context and Interception


slide-1
SLIDE 1

.NET Remoting

Module Subtitle Building distributed applications and implementing attribute-driven behaviors with Microsoft .NET

slide-2
SLIDE 2

Contents

Section 1: Overview Section 2: Remoting Architecture Section 3: Context and Interception Section 4: Serving and Accessing Objects Summary

slide-3
SLIDE 3

Section 1: Overview

Looking back: Remoting in COM(+) What's wrong with that? .NET Remoting Core Concepts

slide-4
SLIDE 4

Looking Back: Remoting in COM(+)

All Objects implement IUnknown interface

Dynamic exploration of object features Lifecycle control with reference counting

DCOM: Object-RPC based on DCE Wire Format Marshaling through MIDL generated Proxies/Stubs

Automation: Dynamic binding through IDispatch

Servers locally advertised in Registry Activation "on-demand"

Servers launched at client request Objects created through class factories

slide-5
SLIDE 5

What’s wrong with that?

DCOM protocol is binary and complex Reference counting difficult to master

Common source of memory leaks for servers Distributed operation require "pinging" clients

Marshaling is non-extensible Registry is difficult to manage; registration clumsy Activation paradigm has component bias

Difficult to locate and connect active servers

Connection oriented protocol

Does not work well on the Internet

slide-6
SLIDE 6

Application Domains

Isolated execution space for applications Independent of OS concept of thread, process Process Process AppDomain AppDomain AppDomain

Object Object Object Object Object

slide-7
SLIDE 7

What is “Remote”, What is” Local”?

"Local" are all objects within the same AppDomain All other objects are "Remote"

Even objects in the same process!

Context-bound objects:

"Local" if they share the same context "Remote" if they are in different contexts

"Local": Not marshaled, immediate object calls "Remote": Marshaled, calls through proxies

slide-8
SLIDE 8

Section 2: Remoting Architecture

What: Messages Where: Channels How: Formatters Marshaling Concepts Proxies

slide-9
SLIDE 9

What to communicate: Messages

Messages are objects that implement IMessage IMessage: Simple dictionary of key/values pairs .NET Message Types:

Construction call messages, response messages Method call messages, response messages

Invocation Styles

Synchronous: Request with immediate response Asynchronous: Request with delayed or no response

slide-10
SLIDE 10

Server

Where to communicate: Channels

Channels transport messages

Built-in channels: TCP, HTTP

Establish endpoint-to-endpoint communication Channels can listen for and send messages

Listen: IChannelReceiver, Send: IChannelSender

Makes no assumptions about endpoint architecture Can implement channel sinks for logging, interception Client Channel "Proxy" Dis- patcher

slide-11
SLIDE 11

How to communicate: Formatters

Formatters serialize .NET objects into wire formats Used dynamically by channel architecture

Configuration-file based association with channels Formatters are implemented as channel sinks

Built-in: SOAP and Binary Formatters

System.Runtime.Remoting.Serialization.Formatters Channel encode into wire format decode from wire format SOAP, Binary, Custom

slide-12
SLIDE 12

Selecting Channels: TcpChannel

System.Runtime.Remoting.Channels.Tcp Uses plain TCP sockets Transmits compact, binary wire format

By default, serialized by the BinaryFormatter .NET native wire-format Fast

Can use custom formatters for other wire-formats Best choice for LAN communication

Uses permanent socket connection

Not recommended for Internet communication

slide-13
SLIDE 13

Selecting Channels: HttpChannel

System.Runtime.Remoting.Channels.Http Uses HTTP 1.1 protocol Transmits SOAP 1.1 XML format

Serialized by SoapFormatter Open standard Basis for W3C SOAP/XMLP Protocol activity

Can use custom formatters for other wire-formats Best choice for Internet communication

Stateless protocol, scales well

Best choice for interoperability and integration

slide-14
SLIDE 14

Selecting Channels: Custom

Bring your own Protocol (APPC,IPX,Pipes, ...) Transmit any format that fits

Can use SoapFormatter or BinaryFormatter Or bring your own formatter: IIOP, RMI, ORPC, ...

Applies to integration scenarios

slide-15
SLIDE 15

The Message Box: IMessageSink

Message Sinks are the .NET message drop-off Implemented by channels to accept messages Implemented by context properties for interception Allows building chains of sinks

Simple linked list through NextSink property Messages can be intercepted, modified or

processed anywhere in the chain

Client Channel "Proxy" IMessageSink

SynchProcessMessage()

  • r AsynchProcessMessage()
slide-16
SLIDE 16

Objects To Go: Marshaling

Definition: Packaging Data for Transfer For objects passed as arguments, return values Marshal-By-Value

Entire object is packaged as-is Copy is transferred to destination No link between copy and original

Marshal-By-Reference

Just a reference to an object is packaged Reference is transferred to destination "Proxy" object links destination with original

slide-17
SLIDE 17

Objects calling Objects: Proxies

"Proxy" Definition

Object that acts locally on behalf of a remote object Looks like and accepts calls as if it were "real" Forwards them to the remote object

Real Proxies

Inherit System.Runtime.Remoting.RealProxy Are the communication layer for transparent proxies

Transparent Proxies

Built dynamically through RealProxy Exact pass-through mirror of the remote object

slide-18
SLIDE 18

Client Server

Proxies illustrated

Channel "Proxy" IMessageSink Transparent Proxy MethodA() MethodB() PropertyQ PropertyP FieldX FieldY Real Proxy

builds Invoke() SyncProcessMessage()

slide-19
SLIDE 19

The Dispatcher

Simplified model:

Located at the channel endpoint Receives messages Builds stack-frame from message content Invokes actual method on object Collects result and creates response message

slide-20
SLIDE 20

Server Dispatcher

The Dispatcher illustrated

Client Channel Object MethodA() MethodB() PropertyQ PropertyP FieldX FieldY StackBuilderSink

SyncDispatchMessage() actual method calls

slide-21
SLIDE 21

Channel Sinks

Formatter, dispatcher and transport are in sinks All channel sinks are linked in chains Client Server StackBuilderSink Server Object Formatter Sink Custom Sinks Custom Sinks Custom Sinks Transport Sink Proxy Client Object Formatter Sink Custom Sinks Custom Sinks Custom Sinks Transport Sink

slide-22
SLIDE 22

Some Advanced Topics

Declaring Methods "One-Way"

Use the "oneway" attribute:

[oneway] void FireAndForget(); [oneway] void FireAndForget();

The Call Context

Property bag passed with every IMessage Dictionary entry "__CallContext", class CallContext Allows to pass processing information along

slide-23
SLIDE 23

Section 4: Serving & Accessing Objects

Remoting Services Exposing Well-Known Objects Exposing Classes for Client-Side Activation Configuring Remoting and Registering Channels Activation and Access

slide-24
SLIDE 24

Remoting Services

System.Runtime.Remoting.RemotingServices class

Provides fundamental remoting infrastructure

Connecting to remote object instances Object marshaling

System.Runtime.Remoting.RemotingConfiguration

Provides infrastructure for Remoting configuration

System.Runtime.Remoting.ChannelServices

Channel registration and management

System.Runtime.Remoting.LifetimeServices

Lease-based lifecycle management for objects

System.Runtime.Remoting.TrackingServices

Universal hooks for tracking remoting activities

slide-25
SLIDE 25

Exposing Well-Known Objects

.NET's activation model is very unlike COM's

.NET rather resembles CORBA model (!)

If there is no actively listening endpoint: no connection No surrogates, no registry, no location transparency EXE servers are not remotely activated

Simplifies Remoting greatly

Expose well-known object for clients to connect.

Bound to known channels with known name Does not use static registration, prog-ids or class-id

Can expose "single call" or "singleton" objects

slide-26
SLIDE 26

Single Call and Singletons

"Single Call" Objects

Object instance is created for each call on channel Implements the stateless model of the web

"Singleton" Objects

One shared instance provided for all clients Serves as "gateway" into stateful application Object is created at registration time

RemotingConfiguration.

RegisterWellKnownServiceType

WellKnownObjectMode.SingleCall WellKnownObjectMode.Singleton

slide-27
SLIDE 27

Server Setup Example

Channels and Objects are AppDomain-Global

Registers the single-call endpoint: http://myserver:8080/MyEndpointURI

Channel registration Object registration

... ... HttpChannel chan HttpChannel chan = new HttpChannel(8080); = new HttpChannel(8080); ChannelServices.RegisterChannel(chan); ChannelServices.RegisterChannel(chan); RemotingConfiguration. RemotingConfiguration. RegisterWellKnownServiceType( RegisterWellKnownServiceType( typeof(ServerClass), typeof(ServerClass), "MyEndpointURI", "MyEndpointURI", WellKnownObjectMode.SingleCall); WellKnownObjectMode.SingleCall);

slide-28
SLIDE 28

Client-Side Activation

Client-Side Activation similar to COM

Client requests creation of remote object Core difference: Server must be running

Server Side Implementation:

Class registered with RemotingConfiguration class

RemotingConfiguration.RegisterActivatedServiceType()

Runtime creates objects on client request

Client Side Implementation:

Object created through Activator class Alternatively: Configuration and language binding

Allows creating remote objects using "new"

slide-29
SLIDE 29

Object Activation and Connection

The Activator (System.Activator)

Creates or connects local and remote objects

Activator.CreateInstance()

Activator.CreateInstance()

Creates client activated objects

Activator.GetObject

Activator.GetObject

Connects to well-known objects

RemotingServices

Connect – lower level connect to remote object

Relationship: Activator uses RemotingServices

slide-30
SLIDE 30
  • = Activator.
  • = Activator.

GetObject("http://..." GetObject("http://...")

  • .methodCall();
  • .methodCall();

Activation illustrated

AppDomain

Context

Object Object Object Object

TCP 8501 HTTP 8080

Identity Table

uriA uriB uriC uriD tcp://server:8501/uriD http://server:8080/uriB

RemotingServices.Connect() Activator.GetObject() Language binding

  • = new
  • = new myClass();

yClass();

  • .methodCall();
  • .methodCall();
slide-31
SLIDE 31

Configuring Remoting

Remoting Configuration Architecture enables:

Definition of endpoints at installation time Well-known ports, full control for administrators Application component distribution by configuration

Configuration can define which classes are remote or local

Configuration is file-based

Integrated with .NET configuration infrastructure However: Must explicitly load

RemotingConfiguration.Configure(“filename“)

Hides most details of Remoting shown here

slide-32
SLIDE 32

Server System Configuration

<configuration> <system.runtime.remoting> <channels> <channel id="http“ type="System.Runtime.Remoting.Channels.Http.HttpChannel, System.Runtime.Remoting" /> </channels> <channelSinkProviders> <serverProviders> <formatter id="soap“ type="System.Runtime.Remoting.Channels. SoapServerFormatterSinkProvider, System.Runtime.Remoting" /> </serverProviders> </channelSinkProviders> </system.runtime.remoting> </configuration> Declare channel Specify formatter

slide-33
SLIDE 33

Server Application Configuration

<configuration> <system.runtime.remoting> <application name="MyFoo"> <service> <wellknown type="Foo, common“

  • bjectUri="Foo.soap“

mode="Singleton" /> </service> <channels> <channel ref="http“ name="MyHttpChannel" port="9000"> <serverProviders> <formatter ref="soap" /> </serverProviders> </channel> </channels> </application> </system.runtime.remoting> </configuration> Associate channel with application Declare singleton service endpoint Associate formatter with channel

slide-34
SLIDE 34

Section 5: Putting It Together

Variations of Objects Context Attributes and Interception

slide-35
SLIDE 35

Variations of Objects 1/2

Agile (never marshaled)

public class MySimpleObject public class MySimpleObject { public MySimpleObject() { } public MySimpleObject() { } }

Agile (marshal-by-value)

[serializable] [serializable] public class MySimpleObject public class MySimpleObject { public MySimpleObject() { } public MySimpleObject() { } }

slide-36
SLIDE 36

Variations of Objects 2/2

Agile (marshal-by-ref, AppDomain-bound)

public class MySimpleObject : public class MySimpleObject : MarshalByRefObject MarshalByRefObject { public MySimpleObject() { } public MySimpleObject() { } }

Context-bound (marshal-by-ref)

[CallTrace()] [CallTrace()] public class MySimpleObject : public class MySimpleObject : ContextBoundObject ContextBoundObject { public MySimpleObject() { } public MySimpleObject() { } }

slide-37
SLIDE 37

Summary

.NET Remoting is open-standards based

... supporting SOAP, XML and HTTP

The infrastructure is extensible at every level

... and useable on every level

.NET Remoting Contexts build on the COM+ idea

... but make contexts available for your extensions

Attribute driven behaviors can be built on Contexts

... to separate plumbing from business code

.NET Remoting is configurable at installation time

... and on an application level

slide-38
SLIDE 38

Questions?