Indigo Training

36
Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 2 Objectives Objectives Review the role and motivations of Indigo Why the drastic change – again? Survey the Indigo architecture Draw parallels to current technologies Look at some Indigo code In the end, that's what its all about right? See how to prepare for Indigo today Because your projects are not on Microsoft's release schedule

description

http://www.Intertech.com This presentation was a pre-release talk on what became WCF.

Transcript of Indigo Training

Page 1: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 2

ObjectivesObjectives

Review the role and motivations of IndigoWhy the drastic change – again?

Survey the Indigo architectureDraw parallels to current technologies

Look at some Indigo codeIn the end, that's what its all about right?

See how to prepare for Indigo todayBecause your projects are not on Microsoft's release schedule

Page 2: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 3

Disclaimer!!Disclaimer!!

Indigo is NOT a finished product!– When released, it will likely look different from what you see today

Take all code examples with a big grain of salt– The specifics will change (attribute names, namespace names, etc)– However, the examples do provide a taste of what programming

Indigo will be like

Page 3: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 4

What is Indigo?What is Indigo?

Indigo is – A set of services for building distributed applications in .NET– A unified programming model to supersede Remoting, Web

services, Enterprise Services, and MSMQ

Indigo will ship– As part of the WinFx release (includes Avalon)– With Longhorn

Indigo will run on– Windows XP– Windows 2003– Windows "Longhorn"

Page 4: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 5

Why Do We Need Indigo?Why Do We Need Indigo?

Too many sides of distributed .NET programming:– Remoting: RPC style, distributed objects, CLR type fidelity, code

integration– Web Services: RPC style, XSD type fidelity, schema/WSDL

integration– Enterprise Services: RPC style, code integration, declarative

services (transactions, pooling, concurrency)– MSMQ: message style, schema or code integration, robust

messaging support (guaranteed delivery, transacted messages)

Result: Confusion reigns!– Questions regarding what to use when– Not easy to rewrite app if you start down the wrong path

Page 5: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 6

Why Do We Need Indigo?Why Do We Need Indigo?

Distributed objects are passé– OO dogma destroys distributed application performance and

scalabilityChatty versus Chunky interfacesStateful versus stateless objects

– Typically, nodes must share code in order to interoperate– OO proves to be an ineffective metaphor for distributed apps on

an enterprise scale

Service Oriented Architecture (SOA) is hip– But current tools favor RPC/distributed objects over SOA– Indigo provides tools to make service orientation easy

But also supports RPC/Distributed Objects!

Page 6: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 7

What is SOA?What is SOA?

SOA is prescriptive guidance for building "connected" applications

The four principles of SOA:– Boundaries are explicit

Contrast to "location transparency"– Services are autonomous

Atomic deployment is a myth

– Services share schema and contractsContrast to sharing DLLs

– Service compatibility is based on policyCompatibility goes beyond schema and contracts

Page 7: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 8

What is SOA?What is SOA?

SOA characteristics– Nodes communicate through structured messages– Uses standard message formats (SOAP, WS-*) and wire protocols

(HTTP, TCP, SMTP)– Achieves platform interoperability– Nodes are deployed independently and evolve independently– Not confined to request/reply semantics (like HTTP)

Indigo supports SOA development, but also:– Can support RPC style communication ala Remoting– Can support pure messaging ala MSMQ

Page 8: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 9

Indigo ArchitectureIndigo Architecture

Indigo is split into 2 layers– The Connector layer exposes a low level programming model– The Services model is the "productivity sweet spot"

Service ModelService Model

Connector LayerConnector Layer

PortsPorts ChannelsChannels MessagesMessages

ServiceService ServiceMethodServiceMethod Declarative Behaviors

Declarative Behaviors

High levelDeclarative

Message or RPC

High levelDeclarative

Message or RPC

Low LevelExtensible

Message Oriented

Low LevelExtensible

Message Oriented

Page 9: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 10

Indigo Indigo –– Connector LayerConnector Layer

The Connector layer exposes 3 main objects:– A Port represents a URL named location in network space– A Message represents a SOAP message in memory– A Channel provides message I/O through the Port

Client AppDomain

Server AppDomainServer AppDomain

Port

Client AppDomain

Port

PortPortChannel1

Channel1

ChannelN

ChannelN

Message

Sending Code

Sending Code

TransportChannel

TransportChannel

ChannelN

ChannelN

Channel1

Channel1

TransportChannel

TransportChannel

Receiving Code

Receiving Code

Page 10: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 11

Indigo Indigo –– Connector LayerConnector Layer

Ports– Establish a base address for your service– Create the necessary channels for message I/O

Channels– Define the message interchange patterns (Simplex, Duplex,

Request/Reply)– Define policy requirements: security, reliability, transactions– Implement a pull mechanism for retrieving messages

Page 11: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 12

Indigo Indigo –– Connector LayerConnector Layer

Messages– Represent a SOAP message in memory– Store and provide access to headers in memory– Provide access to the body via System.Xml types (XmlReader,

XmlBinaryReader)– Message body may be streamed

Page 12: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 13

Indigo Indigo –– The Service ModelThe Service Model

The Service model is the layer most will use– The Connector layer is for plumbers

The Service model – Extends the connector layer– Unifies Web services, Remoting, Enterprise Services into one

programming model– Integrates with the CLR type system and supports

schema/contract generation (WSDL)– Allows both message style and RPC style communication– Provides currency, instance, and session management– Is relatively lightweight (pay-as-you-go mechanism)

Page 13: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 14

Indigo Indigo –– The Service ModelThe Service Model

ProxyService Extensions

channel.Send()

ProxyService Extensions

channel.Send()

Client AppDomainClient AppDomain

Server AppDomain

SessionService Extensionschannel.Receive()

SessionService Extensionschannel.Receive()

Server AppDomain

PortPort

PortPortChannel1

Channel1

ChannelN

ChannelN

Message

Calling Code

Calling Code

TransportChannel

TransportChannel

ChannelN

ChannelN

Channel1

Channel1

TransportChannel

TransportChannel

Service Service

Page 14: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 15

Indigo Indigo –– Service ModelService Model

[Service]public class SimpleMath { [ServiceMethod] private int Add(int n1, int n2) { return n1 + n2; } public int Subtract(int n1, int n2) { return n1 - n2; } }

Named ParamsInteropModeCommonAssemblies

Named ParamsInteropModeCommonAssemblies

[ServiceContract]public interface ISimpleMath { [ServiceMethod] int Add(int n1, int n2); }

Same as [Service], except can only be

applied to interfaces

Same as [Service], except can only be

applied to interfaces

Page 15: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 16

Indigo Indigo –– Service ModelService Model

[Service] public class SimpleMath { [ServiceMethod] private int Add(int n1, int n2) { return n1 + n2; } [ServiceMethod] public int Subtract(Message m) { ... } [ServiceMethod] public Message Multiply(Message m) { ... } [ServiceMethod(Oneway = true)] private void FireAndForget() { ... } }

Service model parses the message for the method params

Service model parses the message for the method params

Or use (Message m) signature to work on the raw message

Or use (Message m) signature to work on the raw message

Oneway property declares that a request/reply channel is not needed

Oneway property declares that a request/reply channel is not needed

Page 16: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 17

Indigo Indigo –– Service ModelService Model

Indigo also provides the RemoteObject attribute– Provides functionality similar to .NET remoting– Use to port .NET Remoting code to use the Indigo messaging layer– WSDL generation is not supported (requires assembly sharing) – Public visibility defines the remote contract

[RemoteObject] public class RemoteMath : MarshalByRefObject { public int Add(int n1, int n2) {} }

Page 17: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 18

Indigo Indigo –– HostingHosting

You can host Indigo services in any Windows exe

However, ASP.NET is the typical hosting choice– Provides additional services: automatic startup, health monitoring,

management– Supports a variety of network protocols: HTTP, TCP/IP– Other hosts require explicit creation of a Port and/or adding a

service to the ServiceManager

Page 18: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 19

Indigo Indigo –– TransactionsTransactions

.NET 2.0 bakes an imperative transaction model– Goal: make transactional programming ubiquitous– For example: use a transaction to update an ArrayList– Defines a set of interfaces and services to make it easier to build

custom RMs

Transactions are an important part of Indigo– "Services are autonomous" assumes reliability and correctness– Indigo extends the imperative model with a declarative model (ala

COM+)

Page 19: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 20

Indigo Indigo –– TransactionsTransactions

System.TransactionsSystem.Transactions

ITransactionITransactionTransactionScopeTransactionScope

TransactionAttributeTransactionAttribute Indigo

.NET 2.0

Lightweight Transaction ManagerLightweight Transaction Manager

Distributed TxCoordinator

Distributed TxCoordinator

Only participates when needed

Kernel TxCoordinator (Longhorn)

Kernel TxCoordinator (Longhorn)

Page 20: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 21

Manual Transactions in .NET 2.0Manual Transactions in .NET 2.0

static void Main() { ICommittableTransaction cTx = Transaction.Create(); Transaction.Current = cTx.Clone(); cTx.Commit(); }

Clone() returns a non-committable Tx object

Subordinates can use this "ambient" Tx to enlist.

This automatically flows through the AppDomain (think Call Context).

Does not flow across Web service boundaries.

Page 21: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 22

Implicit Transactions in .NET 2.0Implicit Transactions in .NET 2.0static void Main() { using(TransactionScope ts = new TransactionScope(TransactionScopeOptions.Required)) { DoSubordinateWork(); // Do work on a transacted resource ts.Consistent = true; } } static void DoSubordinateWork() { using(TransactionScope ts = new TransactionScope(TransactionScopeOptions.Supported)) { // do work on a transacted resource ... ts.Consistent = true; } }

Page 22: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 23

Indigo Indigo –– Declarative TransactionsDeclarative Transactions

Indigo adds declarative Tx attributes – Similar to Enterprise Services– Can apply to any Service method– Service model establishes the ambient transaction

Indigo automatically propagates Tx

Page 23: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 24

Moving to IndigoMoving to Indigo

All your current code will run after you install Indigo– Current protocol stacks can be loaded in the same app domain as

Indigo stack– Therefore: Remoting, Web services, and Enterprise Services, etc.

will just work with no code updates

The 2 questions really are:– Will my remoting/Web services/Enterprise Services/MSMQ based

code interop with Indigo services?– How much code do I change to migrate to the Indigo protocol

stack?

Page 24: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 25

Moving to IndigoMoving to Indigo

Non-trivialYesWSE

Non-trivialYesSystem.Messaging

Simple

Simple

Simple

Migration Path?

NoRemoting

YesASMX (Web services)

YesEnterprise Services

Interop with Indigo?Technology

Page 25: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 26

ASMX To Indigo: Service CodeASMX To Indigo: Service Code

using System.Web.WebServices; public class SimpleMath : WebService { [WebMethod] public int Add(int n1, int n2) { return n1 + n2; } }

using System.ServiceModel [Service] public class SimpleMath { [ServiceMethod] public int Add(int n1, int n2) { return n1 + n2; } }

Page 26: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 27

ASMX To Indigo: Client CodeASMX To Indigo: Client Code

public class MathClient { static void Main() { SimpleMath math = new SimpleMath(); int result = math.Add(5, 2); } } using System.ServiceModel; public class MathClient { static void Main() { SimpleMath math = ServiceManager.CreateProxy<SimpleMath>(); int result = math.Add(5, 2); } }

Page 27: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 28

ASMX To Indigo: NotesASMX To Indigo: Notes

SOAP Extensions will be easy to rewrite

Full support for [WebMethod] and XML serialization attributes

Avoid or abstract calls to HttpContext

ASMX WSDL customization features not supported

Page 28: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 29

.NET Remoting To Indigo: Object Code.NET Remoting To Indigo: Object Code

public class SimpleMath : MarshalByRefObject { public int Add(int n1, int n2) { return n1 + n2; } }

using System.ServiceModel; [RemoteObject] public class SimpleMath : MarshalByRefObject { public int Add(int n1, int n2) { return n1 + n2; } }

Page 29: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 30

.NET Remoting To Indigo: Host code.NET Remoting To Indigo: Host codeusing System.Runtime.Remoting; public class Host { static void Main() { RemotingConfiguration.Configure("remote.config"); Console.WriteLine("Waiting for client requests ..."); Console.ReadLine(); } } using System.ServiceModel;

public class Host { static void Main() { ServiceManager svcMgr = new ServiceManager("http://localhost"); svcMgr.Services.Add("/SimpleMath", typeof(SimpleMath)); Console.WriteLine("Waiting for client requests ..."); Console.ReadLine(); } }

Page 30: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 31

.NET Remoting To Indigo: Client Code.NET Remoting To Indigo: Client Codeusing System.Runtime.Remoting; public class Client { static void Main() { RemotingConfiguration.Configure("remote.config"); SimpleMath math = new SimpleMath(); int result = math.Add(5, 2); } } using System.ServiceModel;

public class Client { static void Main() { SimpleMath math = ServiceManager.CreateProxy<SimpleMath>(); int result = math.Add(5, 2); } }

Page 31: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 32

.NET Remoting to Indigo: Notes.NET Remoting to Indigo: Notes

"Transparent" remoting supported except for "new"

Remoting extension points (Channels, Sinks) not supported– You may no longer need the custom code because the feature is

provided by Indigo (e.g. security)– Indigo provides its own extensibility points via the Channel and

ServiceModel

.NET 2.0 deprecates custom context interception

Page 32: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 33

ES To Indigo: Object CodeES To Indigo: Object Codeusing System.EnterpriseServices; [ComponentAccessControl] [Transaction(TransactionOption.Required)] public class SimpleMath : ServicedComponent { [AutoComplete] [SecurityRole("Manager")] public int Add(int n1, int n2) {} }

using System.ServiceModel; [Service] public class SimpleMath { [ServiceMethod] [TransactionScope] [SecurityRole("Manager")] public int Add(int n1, int n2) {} }

Page 33: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 34

ES To Indigo: NotesES To Indigo: Notes

Most ES code is easily migrated

Full support for transaction, security, and lifetime attributes

Attributes that configure the COM+ catalog are ignored

Indigo provides a new model for QC and LCE– Current related ES attributes are ignored

Page 34: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 35

System.MessagingSystem.Messaging to Indigoto Indigo

No plans for migrating from System.Messaging to Indigo.– Remember, you can still use System.Messaging after you install

Indigo– And you can interop with Indigo services via System.Messaging

Indigo will have its own queuing mechanism– 1st release likely to build on MSMQ– Programming model may be different from System.Messaging

Page 35: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 36

Summary Summary -- Preparing for Indigo TodayPreparing for Indigo Today

Write services using ASMX– Minimize or abstract HTTP Context access– Minimize or abstract SOAP Extensions

Use Enterprise Services/DCOM if– Performance is critical– You need ES features (distributed Tx, object pooling)– You don't mind the extra deployment hassles of DCOM

Use .NET Remoting if– You must implement custom protocols– Performance is critical and you must cross a firewall (cannot open

to DCOM)– You need cross-appdomain communication

Use MSMQ if rich messaging support is required– Use System.Messaging rather than MSMQ APIs

Page 36: Indigo Training

Copyright © Intertech Training 2004 • www.intertechtraining.com • 800-966-9884 • Slide 37

Wrap Up!Wrap Up!

Intertech offers .NET, Java, and XML trainingNow Offering Instructor Lead Virtual Training!

My Books– Distributed .NET Programming in C#

– Distributed .NET Programming in VB.NET

Now Available! Applied .NET Attributes

Questions? Comments?

[email protected]