7.2. Default Binding, Behaviors, and Endpoints

In our previous example, we set a base address for our service to listen to (http://localhost:8888/Chapter7) with the following code, but we didn't actually create any endpoints:

ServiceHost MyServiceHost =
 new ServiceHost(typeof(Chapter7.ConfiglessService.Service1),
         new Uri("http://localhost:8888/Chapter7"));

In WCF4, if you don't specify any endpoints in code or by configuration, then WCF will automatically create a default endpoint for your service (one for each interface your service implements).

The type of endpoint that gets created is dependent on what you use as the base address. In this case, a basicHttpBinding was created, as we used an address starting with http://. However, if the address specified began with net.tcp://localhost:8081/greeting, a netTcpBinding would be used. This is a huge step forward from WCF3.5, which made you create endpoints and would throw an exception if you didn't. Table 7-1 shows the bindings that are used for different addresses.

Table 7.1. Default Protocol Mappings for Different Types of Addresess
AddressBinding
httpbasicHttpBinding
net.pipenetNamedPipeBinding
net.msmqnetMsmqBinding
net.tcpnetTcpBinding

If you are using a configuration file or creating an endpoint in code and still want default endpoints to be created, then you can call the AddDefaultEndpoints() method on your ServiceHost class (MyServiceHost in this example).


7.2.1. Default Binding and Behaviors

WCF allows you to create bindings and behaviors to be used by all endpoints by simply not specifying a configuration or behavior configuration name. This technique could, for example, be used to enable the Metadata Exchange (MEX) endpoint on all services to offer a metadata description for each service:

<behaviors>
   <serviceBehaviors>
    <behavior>
     <serviceMetadata httpGetEnabled="True"/>
    </behavior>
   </serviceBehaviors>
</behaviors>

7.2.2. Standard Endpoints

WCF4 comes packaged with a number of standard or preconfigured endpoints. These endpoints are configured in a manner that Microsoft believes will be suitable for most developers. To use a standard endpoint configuration, simply specify the endpoint name by using the new kind attribute. For example, the following configures an endpoint to use mexEndpoint:

<endpoint kind="mexEndpoint" />

If you want to override the settings of standard endpoints, you can do this in the new <standardEndpoints> section. The WCF4 samples also have an example of creating your own standard endpoint (WCFBasicServicesStandardEndpointsCSService).

Table 7-2 lists the standard endpoints contained within WCF4.

Table 7.2. Standard Endpoint Types
NameDescription
announcementEndpointUsed to send announcements
discoveryEndpointUsed for service discovery
dynamicEndpointNo info at time of writing
mexEndpointUsed for metadata information
udpAnnouncementEndpointUsed to send announcement messages over UDP multicast binding
udpDiscoveryEndpointUsed for discovery operations over UDP multicast binding
webHttpEndpointStandard endpoint with WebHttpBinding binding
webScriptEndpointWebHttpBinding binding with WebScriptEnablingBehavior behavior
workflowControlEndpointUsed for calling control methods on WF instances

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.159.82