Is it possible to have one service with two behavior configurations? As you know it is possible to have one service and more than one endpoint where you can specify different binding configuration. But I need to have, for the same service, different service behaviors.
If I try something like this:
<services>
<service name="Service.Service1" behaviorConfiguration="Behavior1">
<host>
<baseAddresses>
...
</baseAddresses>
</host>
<endpoint ...>
</endpoint>
</service>
<service name="Service.Service1" behaviorConfiguration="Behavior2">
<host>
<baseAddresses>
...
</baseAddresses>
</host>
<endpoint ...>
</endpoint>
</service>
</services>
... I got error "A child element named 'service' with same key already exists at the same configuration scope"
I know that I can create new class that inherits original service class but is there better solution?
Seems that you should register the same service class with another service name. Service behavior is a part of service configuration so if you want to use different behaviors you should configure different services. My question to you: if you will have one service with two behaviors, how wcf will decide to use this one or another? Why you solution with inheritance is bad?
Quite intriguing question... I am not certain if what I am describing is possible but solution would be some thing like below:
Yet another way would be injecting dynamic type named "Service.Service1.Entry1" inherited from Service.Service1 when application is initializing. This part is very much possible - i.e. for every mentioned service, you would create n subtypes dynamically at app start-up so that you can use them as intended.
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