AgileJon
AgileJon

Reputation: 53606

Can I add custom WCF Behaviors from my custom Binding?

I am writing a custom WCF Binding and I want to run some code only if there is a problem processing a message. My thought is to add a custom IOperationInvoker and use a try/catch around the processing of the message. I cannot find a way to add the custom behavior from within my binding. I would like to avoid having to declare BOTH a binding and behavior for any services that want to use this binding.

The model I'm running off of is the Net.Msmq binding, where you can declare retry handling via the binding. That's essentially what I'm trying to replicate, but via my own binding.

Any WCF gurus out there?

Upvotes: 4

Views: 1016

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

I think it is not possible. Binding cannot add behaviors. You can check default WCF bindings - for example WebHttpBinding is always used in conjunction with WebHttpBehavior or WebScriptEnablingBehavior but WebHttpBinding is not able to add them, you must add them manually. To solve this inconvenience WCF offers WebServiceHost class which can be used instead of common ServiceHost. WebServiceHost makes all needed configuration for REST service - it adds WebHttpBehavior and enpoint with WebHttpBinding. You can use the same approach.

But I think this not a good approach. Retry handling is already handled by ReliableSession and it is implemented as channel so you should probably try the same way. In such case you will not need to deal with behavior problem.

Upvotes: 1

Related Questions