26
Building a ServiceHost for your WCF Services - the Right Way! Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog: www.eVardi.com

Servicehost Customization

Embed Size (px)

DESCRIPTION

There’s no doubt that building a distributed system with WCF is much easier than with any other Microsoft technology. But, how can we be sure that we are doing it the right way? In this session we will go over common scenarios developer face when building and hosting WCF services: 1. Error handling 2. Serialization issue 3. Choocing the instanse model 4. Extendable object and see how widening the WCF ServiceHost in the infrastructure level can help us to build a robust, reliable and manageable system.

Citation preview

Page 1: Servicehost Customization

Building a ServiceHost for your WCF Services - the Right Way!

Eyal VardiCEO Experts4DMicrosoft VSTO MVPblog: www.eVardi.com

Page 2: Servicehost Customization

AgendaAgenda

Service Description

Service Pipeline

Serialization issue

Extensible Object Pattern

Error Handler

Q&A

Summary

Page 3: Servicehost Customization

ConsultinConsultingg

MentorinMentoringg

ProjectsProjects

Page 4: Servicehost Customization

Service Description Service Description (Metadata)(Metadata)

It describe all aspects of the service, endpoints & behaviors ( A, B, C, Be )

new ServiceHost( typeof(Hello) )

ServiceServiceDescriptioDescriptio

nn

ConfigConfig

Service HostService Host

ServiceService

InterfacesInterfaces

CodeCode

Service Model Service Model LayerLayer

Message LayerMessage LayerWSDLWSDL

Page 5: Servicehost Customization

Configuration Manager for Configuration Manager for WCFWCF

Application LauncherApplication Launcher

ServiceHosServiceHostt

ServiceHosServiceHostt

ServiceHosServiceHostt

IdId IdId IdId

Config ManagerConfig ManagerConfig ManagerConfig Manager

Page 6: Servicehost Customization

ServiceHost(Service Description)

Page 7: Servicehost Customization

Inside WCF Pipeline Inside WCF Pipeline (Receiver)(Receiver)

Message Message LayerLayer

Service Model LayerService Model Layer

ServiceServiceDescriptioDescriptio

nnBehaviorBehaviorss

ServiceService

Page 8: Servicehost Customization

Service HostService Host

Channel Channel DispatcherDispatcher

EndpointEndpoint Dispatcher Dispatcher

DispatchDispatchRuntimeRuntime

DispatchDispatchOperatioOperatio

nn

Service Service DescriptionDescription

EndpointEndpoint

ContractContract

BindingBinding

OperatioOperationn

MessaMessagege

IIServiceServiceBehaviorBehavior

IIEndpointEndpointBehaviorBehavior

IIContractContractBehaviorBehavior

IIOpertionOpertionBehaviorBehavior

How to manipulate the How to manipulate the pipelinepipeline

Page 9: Servicehost Customization

WCF Behavior ClassesWCF Behavior Classes WCF have built-in WCF have built-in attributeattribute and and

configuration element configuration element to to customize the pipeline.customize the pipeline.

Page 10: Servicehost Customization

ServiceService

WCF Pipeline Configuration WCF Pipeline Configuration OptionsOptions

CDCD

EDED

EDED

DRDR

DRDR

DODO

DODO

DODO

DODO

ServiceThrottle ErrorHandlers Endpoints Timeouts

ServiceThrottle ErrorHandlers Endpoints Timeouts

Address Filter Contract Filter

Address Filter Contract Filter

MethodMethodMethodMethod

MethodMethodMethodMethod

MethodMethodMethodMethod

MethodMethodMethodMethod

CContractontract BeBehaviorshaviors

Message Behavior Instance Behavior Security Behavior

Message Behavior Instance Behavior Security Behavior

Formatter Parameter Inspector Invoker

Formatter Parameter Inspector Invoker

Page 11: Servicehost Customization

Error Handling ExtensionsError Handling Extensions

ServiceThrottle ErrorHandlers Endpoints Timeouts

ServiceThrottle ErrorHandlers Endpoints Timeouts

Page 12: Servicehost Customization

Error Handler

CCDD EDED DD

RRDDOO

Error Error HandlersHandlers

Error Error HandlersHandlers

Page 13: Servicehost Customization

The Extensible Object The Extensible Object PatternPattern Extend existing runtime classes with:

New functionality New state to an object

Page 14: Servicehost Customization

Persistence State in Persistence State in ServiceService

Page 15: Servicehost Customization

Persistence State in Persistence State in ServiceService

SerivceSerivceSerivceSerivceSerivceSerivce

Instance ContextInstance Context

Service HostService Host

ExtenstioExtenstionn

ExtenstioExtenstionn

Page 16: Servicehost Customization

Extensible Object

CCDD EDED DD

RRDDOO

Extensible Extensible ObjectObject

Extensible Extensible ObjectObject

Page 17: Servicehost Customization

Instance PoolInstance Pool

Page 18: Servicehost Customization

Instance Pool

CCDD EDED DD

RRDDOO

Instance PoolInstance PoolInstance PoolInstance Pool

Page 19: Servicehost Customization

Serialization IssueSerialization Issue

public UserInfoUserInfo EchoUser ( int userIduserId );

EncodingEncoding

DeserializationDeserializationSerializationSerialization

EncodingEncodingBin

din

Bin

din

ggTra

nsp

oTra

nsp

ortrt

Page 20: Servicehost Customization

DispatchOperation.FormattDispatchOperation.Formatter er

Type coupled coupled Loosely coupledcoupled Known Type Known Type IExtensibleDataObject

DeserializeRequestDeserializeRequest

SerializeReplySerializeReply

Page 21: Servicehost Customization

OO Formatter

CCDD EDED DD

RRDDOO

FormatterFormatterFormatterFormatter

Page 22: Servicehost Customization

Serialization issue ExampleSerialization issue Example

ConsumeConsumerr

infrastructureinfrastructure

ProviderProvider

Page 23: Servicehost Customization

OO Formatter

CCDD EDED DD

RRDDOO

OO FormatterOO FormatterOO FormatterOO Formatter

Page 24: Servicehost Customization
Page 25: Servicehost Customization

SummaSummaryry Service Description

Service Pipeline

Serialization issue

The Extensible Object Pattern

Error Handler

Page 26: Servicehost Customization

ResourcesResources

www.Experts4D.com / Eyal www.NetFX3.com http://code.msdn.com/wcfvisualizer