次の方法で共有


Behaviors can't really mess with the contract directly

This is something that tripped me up for a while, so I figure that
while I'm dumping little tidbits I might as well offer this one. When
you implement an I*Behavior, the Apply*Behavior methods you are passed
a ServiceDescription, or ContractDescription, or EndpointDescription.
There is this implication that you can, in a behavior, modify that
contract or service other than to merely add your particular customization object.

It's not true. The description you have been handed is not the one used
at runtime. If you try, as I did once, to create new endpoints in your
behavior, you'll find that it doesn't work. So if you really do want to
participate in the service description creation process, then extend
ServiceHost or participate in the Opening process.