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.
Address | Binding |
---|---|
http | basicHttpBinding |
net.pipe | netNamedPipeBinding |
net.msmq | netMsmqBinding |
net.tcp | netTcpBinding |
|
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>
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.
18.221.80.42