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?
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.
A bit late for an answer but
following is in a nutshell what turned the light on for me (cudo's to Fred Yang)
ServiceContract
ServiceBehavior
From ServiceContract vs ServiceBehavior
In WCF, ServiceContract attribute affect the behavior of both client and server, while ServiceBehavior only affect the behavior of server. ServiceContract can apply both to interface and class, but ServiceBehavior can only apply to class implementation. ServiceContract affect the wsdl emitted, but ServiceBehavior will not affect wsdl emitted.
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With