I. Overview
Configuration is also a major component of WCF programming. In previous. net applications, we wrote DBConn and some dynamic loading classes and variables in the configuration file. However, WCF is different. It specifies the service exposed to the client, including the service address, the transmission and encoding of the service for sending and receiving messages, and the security type required by the Service. After using the configuration file, we can modify the changed information of WCF without compiling, which improves the flexibility of the program.
If the configuration is written in the Code, the configuration file does not work.
The Web program is configured in Web. config, and the application is configured in App. config.
Ii. service configuration
Configure the service node in Config as <system. serviceModel> </system. serviceModel>. The node contains three levels. The following code is used:
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <configuration> 3 <system. serviceModel> 4 5 <! -- Configure service and endpoint start --> 6 <services> 7 <service> 8 <endpoint> </endpoint> 9 </service> 10 </services> 11 <! -- Configure the service and end point --> 12 13 <! -- Start binding configuration --> 14 <bindings> 15 <netTcpBinding> 16 <binding> 17 </binding> 18 </netTcpBinding> 19 </bindings> 20 <! -- End of configuration binding --> 21 22 <! -- Configure behavior start --> 23 <behaviors> 24 <serviceBehaviors> 25 <behavior> 26 </behavior> 27 </serviceBehaviors> 28 </behaviors> 29 <! -- Configuration behavior ended --> 30 31 </system. serviceModel> 32 </configuration>
Service configuration section [required]: Configure services, interfaces, and endpoints. Each Service has the following two attributes. Name: namespace. class name [service implementation class]. BehaviorConfiguration: Name found in the behaviors node.
Binding configuration section [Optional]:Configure binding, such as http and tcp.
Behavior configuration section [Optional]: Configure behaviors, such as authentication.
Iii. Instances
1 <? Xml version = "1.0"?> 2 <configuration> 3 <system. serviceModel> 4 5 6 <! -- Service --> 7 <services> 8 <! -- Name: namespace. type name --> 9 <! -- BehaviorConfiguration: behavior name. For details, see the name of the behavior configuration section --> 10 <service name = "WCFLibrary. user "behaviorConfiguration =" MyBehavior "> 11
Iv. Copyright
Reprinted please indicate the source: http://www.cnblogs.com/iamlilinfeng