tags:

views:

30

answers:

2

In WCF, what is the difference between a Behaviour and a Contract? From examining the config file, both seem to point to the interface of the service functionality. Why are they both needed?

+2  A: 

The Contract is the interface -- it defines the service operations exposed by the WCF service, which may or may not correspond 1:1 to an unadorned code interface your application.

The Behavior is an implementation of that interface on the host -- for all intents and purposes, "the service."

Jay
+3  A: 

The Cole's Notes version:

  • The Contract specifies what the service actually does. In other words, what Operations are valid.

  • The Endpoint specifies an actual running instance of the service. It is the actual "service" in the sense that it executes, either as a Windows Service or under IIS.

  • The Service Behavior defines how the endpoint interacts with clients. Attributes like security, concurrency, caching, logging, etc. - those are all part of the behavior.

  • There is also an Operation Behavior which is similar to the Service Behavior but only gets applied when a specific operation is run.

For more information I suggest you start with the WCF Architecture Overview.

Aaronaught