Exercise 2: Service Behaviors

In WCF Service Behaviors, modify the way a service works. Without any configuration your service does not have metadata (WSDL) enabled so you cannot test it or add a service reference to it.

Previously in WCF3, when you wanted to apply service behavior, you had to create a named serviceBehavior and apply the behaviorConfiguration to a named service.

In WCF4, when you create an unnamed service behavior it applies to all unnamed services. In this exercise, you will enable some service behaviors.

Task 0 – Opening the Solution

To begin this exercise you can use the solution you finished from Exercise 1. Alternatively, you can follow the following steps to begin with Exercise 2.

  1. Open the starting solution for Exercise 2 located under the Source\Ex2-ServiceBehavior\Begin (choosing the folder that matches the language of your preference.) Use it as the starting point for this exercise.
  2. Press CTRL+SHIFT+B to build the solution.

Task 1 – Enabling Behaviors

  1. Open Web.config.
  2. Uncomment the <system.serviceModel> section. Your service will now have the serviceMetadata behavior and serviceDebug behavior enabled

    Note:
    What services will this behavior apply to?

    Services without named configuration get the default behaviors declared in Web.config. If you want a service to have different behaviors add a <service> tag and define a named behavior.

Next Step

Exercise 2: Verification