# 简化配置Simplified Configuration

## 简化配置Simplified Configuration

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="false">
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name=MyBindingConfig"
maxBufferSize="100"
</basicHttpBinding>
</bindings>   <services>
<service behaviorConfiguration="MyServiceBehavior"
name="MyService">
binding="basicHttpBinding"
contract="ICalculator"
bindingConfiguration="MyBindingConfig" />
binding="mexHttpBinding"
</service>
</services>
</system.serviceModel>


.NET Framework 4.6.1.NET Framework 4.6.1 通过 <service> 元素删除要求，使 WCF 服务配置更容易。makes configuring a WCF service easier by removing the requirement for the <service> element. 如果未 < service > 部分添加或在 < service > 部分中添加任何终结点，并且服务未以编程方式定义任何终结点，则会将一组默认终结点自动添加到服务中，每个服务基址对应一个终结点。和服务实现的每个协定。If you do not add a <service> section or add any endpoints in a <service> section and your service does not programmatically define any endpoints, then a set of default endpoints are automatically added to your service, one for each service base address and for each contract implemented by your service. 在上述每个终结点中，终结点地址与基址相对应，绑定由基址方案确定，协定即为服务实现的协定。In each of these endpoints, the endpoint address corresponds to the base address, the binding is determined by the base address scheme and the contract is the one implemented by your service. 如果你不需要指定任何终结点或服务行为，或者不需要更改任何绑定设置，则完全不必指定服务配置文件。If you do not need to specify any endpoints or service behaviors or make any binding setting changes, you do not need to specify a service configuration file at all. 如果服务实现了两个协定，并且主机同时启用了 HTTP 和 TCP 传输，服务主机将创建四个默认终结点，使用每个传输的每一协定各对应一个终结点。If a service implements two contracts and the host enables both HTTP and TCP transports the service host creates four default endpoints, one for each contract using each transport. 若要创建默认终结点，服务主机必须了解要使用的绑定。To create default endpoints the service host must know what bindings to use. 这些设置在 "< system.serviceModel >" 部分的 < protocolMappings > "部分中指定。These settings are specified in a <protocolMappings> section within the <system.serviceModel> section. "<protocolMappings>" 部分包含映射到绑定类型的传输协议方案的列表。The <protocolMappings> section contains a list of transport protocol schemes mapped to binding types. 服务主机使用传递到它的基址来确定要使用的绑定。The service host uses the base addresses passed to it to determine which binding to use. 下面的示例使用 < protocolMappings > 元素。The following example uses the <protocolMappings> element.

<protocolMapping>
</protocolMapping>


"<protocolMappings>" 部分中的每个元素必须指定方案和绑定。Each element within the <protocolMappings> section must specify a scheme and a binding. 还可以指定一个 bindingConfiguration 属性，该属性在配置文件的 < bindings > 部分中指定绑定配置。Optionally it can specify a bindingConfiguration attribute that specifies a binding configuration within the <bindings> section of the configuration file. 如果未指定 bindingConfiguration，则使用相应绑定类型的匿名绑定配置。If no bindingConfiguration is specified, the anonymous binding configuration of the appropriate binding type is used.

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
</behavior>
</serviceBehaviors>
</behaviors>    <!-- No <service> tag is necessary. Default endpoints are added to the service -->
<!-- The service behavior with name="" is picked up by the service -->
</system.serviceModel>


<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="100"
</basicHttpBinding>
</bindings>
<!-- No <service> tag is necessary. Default endpoints will be added to the service -->
<!-- The service behavior with name="" will be picked up by the service -->
<protocolMapping>