29
Satisfy Your Technical Curiosity Beyond ABC: Beyond ABC: WCF practices from the WCF practices from the field field Christian Weyer Christian Weyer thinktecture thinktecture Co-Founder & Solution Architect Co-Founder & Solution Architect http://www.thinktecture.com/staff/ http://www.thinktecture.com/staff/ christian christian [email protected] [email protected]

Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Embed Size (px)

DESCRIPTION

Satisfy Your Technical Curiosity What To Expect ABC 101 – still ABC 101 – still WCF Internals 101 ContractBindingSerializationHostingConsuming State Management SecurityFaultsMonitoring

Citation preview

Page 1: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity

Beyond ABC:Beyond ABC:WCF practices from the fieldWCF practices from the field

Christian WeyerChristian Weyerthinktecturethinktecture

Co-Founder & Solution ArchitectCo-Founder & Solution Architect

http://www.thinktecture.com/staff/christianhttp://www.thinktecture.com/staff/[email protected]@thinktecture.com

Page 2: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity

Beyond ABC:Beyond ABC:WCF practices from the fieldWCF practices from the field

Christian WeyerChristian Weyerthinktecturethinktecture

Co-Founder & Solution ArchitectCo-Founder & Solution Architect

http://www.thinktecture.com/staff/christianhttp://www.thinktecture.com/staff/[email protected]@thinktecture.com

Page 3: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

What To ExpectWhat To ExpectABC 101 – still ABC 101 – still WCF Internals 101WCF Internals 101

ContractContractBindingBindingSerializationSerializationHostingHostingConsumingConsumingState ManagementState ManagementSecuritySecurityFaultsFaultsMonitoringMonitoring

Page 4: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

ABC 101

Page 5: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Client Service

WCF: Bird’s Eye View

EndpointEndpoint

Endpoint

Endpoint

Page 6: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

WCF: Address, Binding, Contract

Service

CBA

CBA

Client

ABC

AddressWhere?

ContractWhat?

BindingHow?

EndpointEndpoint

CBA

Page 7: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Internals 101

Page 8: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Client Codeparameters

Client Runtime

Channel

Channel

Transport Channel

byte[]

Encoder

Service Typeparameters

Dispatcher Runtime

Channel

Channel

Transport Channel

byte[]

Encoder

Message Inspector

Custom Channel

Custom Transport

Custom Encoder Custom Encoder

Custom Transport

Custom ChannelCustom Channel

Custom Channel

Message InspectorOperation Selector

Parameter InspectorOperation Invoker

Message FormatterParameter Inspector

Message Formatter

* Added by configuring the runtime with behaviors* Added by adding binding elements to the binding

ContractWSDL ExporterWSDL ExporterContractWSDL ImporterWSDL Importer

Channel Layer

Service Model Layer

Page 9: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Layered Extensibility

Protocol Channel(s)

Transport Channel

Service Model Extensibility(local only)

Channel Extensibility(affects the wire)

Protocol Channel(s)

Transport Channel

Client Runtime

Dispatch Runtime

Page 10: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Beyond ICalculator

Page 11: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

‚Distributed‘ Hot SpotsOverall architecture, service orientationWCF contract designWCF bindingsWCF without sessionsWCF duplex and callbacksWCF streamingWCF hostingWCF proxy handlingClient threadingData access & notification

Page 12: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

More ‚Distributed‘ Hot SpotsWF custom activitiesWF persistence, tracking, workflow monitoringWF and WCF integrationUnit and Load TestingDebuggingTracing & Logging

Page 13: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Contract Modeling

Message Exchange Pattern (MEP)One-Way, Request-Reply, Notifications, DuplexData

Serialization rules

FaultsMessages

Implicit or explicit

Try thinking decoupled

Page 14: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Contract Modeling

Set Name, Namespace, Action, ReplyActionAlso on ServiceBehavior and binding

POX/REST-style contract with Message typeAddressable from any HTTP-enabled codeImproved in Orcas

Interop with Java still a stretchBasic stuff worksTry to flatten WSDL and XSDsVast interop needs to be proven

Page 15: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Binding Selection„Choose whatever binding with whatever contract“ is not trueAlmost all out-of-the-box bindings are pretty much useless in real world

Change their settingsCreating custom bindings

Custom bindings make up your dayImprove configurability with user-defined binding and custom config

Usually, you need one transport

Page 16: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Binding Selection

Binary encoding over HTTP in self-host looks like a winner in many scenarios

Always perf and load test for your scenario; no ‚guessing‘

Quotas do not get communicated to clientsBuild custom message encoder, e.g. for emitting raw data

Page 17: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

SerializationWCF supports two serializers out-of-the-box

DataContractSerializer (DCS)XmlSerializer (XS)

DCS is new in .NET 3.0 and optimized for WCF‘s worldSupports a large list of serialization mechanisms

We can use e.g. NetDataContractSerializer to support object graphs and type informationWe can create our own serializer and hook it inIn a lot of cases we need to revert back to XS for schema-based contract-first (Web) services modelling or for improved interop

Page 18: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

HostingPlease, use console applications only for testingHosting in NT Service is straight-forward

Leverages Windows SCM featuresThink about exception handling and logging

WCF services should run as non-adminHTTP.sys must be configured

IIS is robust, mature and scalesIIS hosting has some overhead due to additional layeringStreaming from inside IIS seems to have some problems

Windows Process Activation Service (WAS) brings non-HTTP transports into the IIS picture

Only on Windows Vista and Longhorn ServerSame caveats still apply

Page 19: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

ConsumingWCF offers svcutil.exe and/or ‚Add Service Reference…‘ in Visual Studio to generate proxy code and config

svcutil.exe provides countless options but is a bit buggyChannelFactory<T> is a nice WCF class to leverage

Use custom code generation tools to create your own ChannelFactory<T> or ClientBase<T> based client code

Beware of ICommunicationObject-specific trapsOpen(), Close(), Abort() and cleanup cycle

Always catch the ‚correct‘ exceptionsThink about caching the ChannelFactory – it is very expensive to create

Page 20: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

State ManagementThere is no ‚stateless‘ at all

Our applications deal with… well: data – and data is stateDefine what data needs to be accessible when and whereEnforce mode e.g. through sessionless contracts

[ServiceContract(SessionMode=SessionMode.NotAllowed)]

Beware of sessions semanticsnetTcp and namedPipes have implicit channel-based session semantics; as well as wsHttpBinding

Try to avoid session affinity for scalability and robustness reasons

Of course there are cases for using sessions

Page 21: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Security„Secure, Reliable, Transacted!“ – yawn.Fact is that WCF really has almost any support for security-related scenarios we can imagine

It is just quite tedious in v1 to set it upIf you do not need interop and do not need federation always try to think transport security first

It is mature, it is integrated, it is fastCustom bindings can be used to enable and setup security in a controlled way

Security interop is still a ‚miracle‘

Page 22: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

Faults

SO says that no exceptions should leave the serviceSo far for the theory

WCF can transmit exception details inside of a generic fault message

Enable through ServiceBehaviorKnow about the implications

Global IErrorHandler implementation can make error and fault handling even more robustXmlSerializer can not deal with fault information

Page 23: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical CuriositySatisfy Your Technical Curiosity

MonitoringWCF has vast features for tracing, logging and monitoring

WMIPerformance CountersMessage Logging‚Activity‘ TracingHook up your own tracing

SvcTraceViewer tool looks complicated but is very useful for diagnosingMOM pack as SDK sample available

Page 24: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity

Real-World CheckWCF is here and WCF rocks

But is still it is a v1We are currently moving from collecting ‚practices‘ to ‚best practices‘ – slowly

Guidance beyond Hello World and ICalculatorIf something is not here we can hook up our own implementation

Not always is WCF the hammer, as not always everything is a nail

Page 25: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity

Sample Application: YAPOS ?

Yet Another Purchase Order Scenario?No, don’t fear.

Let’s bring some coolness into our dev life – talk about developer videos and mediaEvery ‘good’ developer these days needs to deal with online resources and multimedia content

MSDN.TVChannel 9Dotnetpro.tv (German)

Page 26: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity

Sample Application Scenario

Media Service

Reviewer

User

Upload Service

MessageQueue

MessageQueue

Web Server

Web Server

New MediaService

Page 27: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity

Page 28: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity

Resources

Email Christian [email protected]

Weblog Christian Weyerhttp://blogs.thinktecture.com/cweyer

thinktecturehttp://www.thinktecture.com

Page 29: Satisfy Your Technical Curiosity Beyond ABC: WCF practices from the field Christian Weyer thinktecture Co-Founder & Solution Architect

Satisfy Your Technical Curiosity