More on Behavior Configuration
The service metadata behavior demonstrated in the previous section is just one of many such ready-to-use behaviors, and you will see many examples in the subsequent chapters. You can configure behaviors at the service level (as with the metadata behavior) or at the endpoint level:
<services>
<service name = "MyService" behaviorConfiguration = "MyServiceBehavior">
<endpoint behaviorConfiguration = "MyEndpointBehavior"
...
/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name = "MyEndpointBehavior">
...
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name = "MyServiceBehavior">
...
</behavior>
</serviceBehaviors>
</behaviors>Similar to default bindings, WCF allows for the notion of a
default behavior. A default behavior is a nameless
behavior (either a service or an endpoint level) that implicitly affects
all services or endpoints that do not explicitly reference a behavior
configuration. For example, consider the services MyService1, MyService2, and MyService3. To add the service metadata
exchange on all services in the application, you can use this config
file:
<services>
<service name = "MyService1">
...
</service>
<service name = "MyService2">
...
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>Along with this hosting code:
ServiceHost host1 = new ServiceHost(typeof(MyService1)); ServiceHost host2 = new ServiceHost(typeof(MyService2));
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access