Search code examples
wcfwcf-data-serviceswcf-ria-serviceswcf-bindingwcf-security

Muliple Service Behaviors to same service in WCF


Can we attach multiple service behaviors to the same service in WCF.If yes how can we do that - via config file or as attributes?


Solution

  • Yes, you can.

    ServiceEndpoint has a Behaviors collection. So if you create a service in C# code, you may add any behavior to this collection: standard or your one. The example of how to create custom behavior and add it to the endpoint see here. Keep in mind that you can create and add as many behaviors as you need.

    If you want to add behaviors in the configuration, you will need to create Behavior configuration extension. Here is an example hot to create it and add it to the endpoint in config file.

    EDIT:

    Service behaviors can be added in absolute same way