WCF (4) configuration file (configuration file)

Source: Internet
Author: User

The previous section roughly introduced several basic concepts of WCF. any new technology can bring us a lot of basic concepts. of course, WCF is no exception. more concepts about WCF will be discussed later. we will first discuss how to use this technology without a deep understanding of the many academic definitions.

In the development process, the use of configuration file is flexible: there will be configuration changes in the future, you do not have to re-compile the code, you just need to open the configuration file to change it, save time and effort.

The position of configuration file in WCF cannot be ignored. of course, we can use code to implement each stage of the WCF Service. however, our software products need to be used by customers in actual work. we need to make the maintenance of software products as simple as possible, saving time and effort.

The core of WCF is service. A service contains multiple endpoints, such:

Open vs2010, file --> new project. Select the WCF Service library template. We use the default solution name and project name. Click OK.

Create a WCF library project. Open the app. config file and you will see the following content:

 1 <?xml version="1.0" encoding="utf-8" ?> 2 <configuration> 3  4   <system.web> 5     <compilation debug="true" /> 6   </system.web>  7   <system.serviceModel> 8     <services> 9       <service name="WcfServiceLibrary4.Service1">10         

Note:

Row 1st defines the version of the XML file and the character set used. It is the basic information about the configuration file and is irrelevant to the program configuration. Just keep the default configuration.

Line 3: <configuration> node. configurations in the program must be included in the node.

Line 3 is about debug configuration. If it is in the development stage, set it to true, so that debugging is convenient.

Line 7-31, which is <system. servicemodel> node. The core configuration of the WCF Service is in this node. the node has two subnodes: <services> and <behaviors>. in addition, you can also have <bindings> and so on. <services> is a collection of <service>, <behaviors> is a collection of <behavior>, and <bindings> is a collection of <binding>.

More: Pay attention to two models for WCF programming: one is the programming model and the other is the communication model. generally, we only need to program the model for web development, and send the communication to HTTP. however, WCF allows us to use communication protocols other than HTTP. therefore, we have considered programming and the communication model. fortunately, WCF provides us with convenience: It shields developers from processing the communication model. We only need to create a communication model through the bindings API. therefore, we specify bindings to process the communication model.

Line 8-22 is <services> node, which contains multiple <service> nodes.

Row 9-21 is <service> node. Its name specifies the class name (full name, including namespace) that implements this service ). the <services> has one

Row 3:

Line 11-13: <baseaddress> node, <add> Add a base address of the service. The address in <endpoint> is relative to the address of this baseaddress. if multiple baseaddresses exist, the binding method specified by <endpoint> matches the baseaddress format. (For example, if the binding method specified by <endpoint> is nettcpbinding. TCP: // hitting the baseaddress .)

Row 3, <endpoint> node, <endpoint> In addition to name, has three most important components, namely ABC. A is address, B is binding, and C is contract. address can be a complete URL or a URL relative to the base address. If it is null, the base address is used. binding specifies the communication model such as HTTP, TCP, and mssq. contract is the contract of the service (that is, the Service Interface we modified using [operationcontract ).

The second row is the <endpoint> of metadata, and some metadata information is used and published.

Come here first .....

 

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.