Tutorial 4 [WCF configuration file]

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.