The configuration file of WCF is not complex. Compared with the manual configuration file, I prefer to use the tool "service configuration Editor" that comes with the SDK ". With this tool, we can easily create or modify server and client configuration files.
Basic elements of the WCF configuration file:
<System. servicemodel>
<Services>
<Service>
<Endpoint/>
</Service>
</Services>
<Bindings>
<! -- Specify one or more of the system-provided binding elements,
For example, <basichttpbinding> -->
<! -- Alternatively, <custombinding> elements. -->
<Binding>
<! -- For example, a <basichttpbinding> element. -->
</Binding>
</Bindings>
<Behaviors>
<! -- One or more of the system-provided or custom behavior elements. -->
<Behavior>
<! -- For example, a <throttling> element. -->
</Behavior>
</Behaviors>
</System. servicemodel>
The configuration information of WCF must be written in APP. config or web. config. I think it is better to use a separate configuration file like remoting. In current project development, various components write information to app. config, which is very messy and not easy to maintain.
When compiling the server configuration file, remember to add servicemetadata behaviors. Otherwise, we cannot use svcutil.exe or vs2005 to create the client proxy file.
A demo of the following configuration files:
Server app. config
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<System. servicemodel>
<Services>
<Service behaviorconfiguration = "newbehavior" name = "learn. Library. WCF. myservice">
<Host>
<Baseaddresses>
<Add baseaddress = "http: // localhost: 8080/myservice"/>
</Baseaddresses>
</Host>
<Endpoint address = "" binding = "basichttpbinding"
Contract = "learn. Library. WCF. icontract"/>
<Endpoint address = "mex" binding = "mexhttpbinding"
Contract = "imetadataexchange"/>
</Service>
</Services>
<Behaviors>
<Servicebehaviors>
<Behavior name = "newbehavior">
<Servicemetadata httpgetenabled = "true"/>
</Behavior>
</Servicebehaviors>
</Behaviors>
</System. servicemodel>
</Configuration>
Client app. config
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<System. servicemodel>
<Client>
<Endpoint address = "http: // localhost: 8080/myservice" binding = "basichttpbinding"
Contract = "leleapplication1.localhost. icalculate"
Name = "basichttpbinding_icalculate"/>
</Client>
</System. servicemodel>
</Configuration>
When the "add service reference..." function of vs2005 is used, the client proxy file and configuration file are automatically created.
--------------
Service configuration editor usage graphic demonstration
1. Open the editor and create a new configuration file.
2. Create new service settings.
3. Enter the service manually or use "browser..." to select the service.ProgramSet.
4. confirm that the contract is correct.
5. Select the communication mode.
6. Select the operation method.
7. Clear the endpoint address and ignore the prompt. We will use the host configuration later to facilitate future path adjustment.
8. Complete service settings.
9. View service settings.
10. Add service behavior settings.
11. Add servicemetadata to publish metadata.
12. Set httpgetenabled to true.
13. Modify the service behavior settings.
14. Add a base address on the host so that all other related addresses can use the local path for future maintenance and modification.
15. Add a new service endpoint for configuring WS-metadataexchange. (Optional)
16. Pay attention to the parameter settings of metadataexchange.
17. Save the configuration file.
18. Run the server and enter host base address in the browser to view the Service Page.
19. Click the link to view the WSDL information.
The client configuration method is relatively simple and will not be demonstrated. (Reprinted)