Sunday 27 September 2009

WCF service behavior

Unlike the contracts and the addresses a behavior does not always affect both client and server. A behavior can be local and affect only the server sides way of processes the messages.

A behavior is not exposed as part of metadata.

A behavior can either be a service behavior or an endpoint behavior:

Service Behaviors (behaviors which implement IServiceBehavior


A typical service behavior is the debug logging behavior, which is enabled by adding a serviceBehavior in the config file.

Like this:
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>

One thing that is important to remember is to associate the service with this behavoir. like this:

<services>
<service behaviorConfiguration="ServiceBehavior" name="host.HelloIndigoService">
[...]
</service>

Behaviors can of cause also be added programmatically.

Endpoint Behaviors(behaviors which implement IEndpointBehavior



A endpoint behavior is defined in the same way, but here its not associate with a service but with the actual endpoint.

No comments: