How to: Configure a Basic Windows Communication Foundation Client
This is the fifth of six tasks required to create a basic Windows Communication Foundation (WCF) application. For an overview of all six of the tasks, see the Getting Started Tutorial topic.
This topic discusses the client configuration file that was generated using the Add Service Reference functionality of Visual Studio or the ServiceModel Metadata Utility Tool (Svcutil.exe). Configuring the client consists of specifying the endpoint that the client uses to access the service. An endpoint has an address, a binding, and a contract, and each of these must be specified in the process of configuring the client.
Configure a Windows Communication Foundation client
Open the generated configuration file (App.config) from the GettingStartedClient project. The following example is a view of the generated configuration file. Under the <system.serviceModel> section, find the <endpoint> element.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <!-- specifies the version of WCF to use--> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5,Profile=Client" /> </startup> <system.serviceModel> <bindings> <!-- Uses wsHttpBinding--> <wsHttpBinding> <binding name="WSHttpBinding_ICalculator" /> </wsHttpBinding> </bindings> <client> <!-- specifies the endpoint to use when calling the service --> <endpoint address="http://localhost:8000/ServiceModelSamples/Service/CalculatorService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator" contract="ServiceReference1.ICalculator" name="WSHttpBinding_ICalculator"> <identity> <userPrincipalName value="firstname.lastname@example.org" /> </identity> </endpoint> </client> </system.serviceModel> </configuration>
This example configures the endpoint that the client uses to access the service that is located at the following address:
The endpoint element specifies that the
ServiceReference1.ICalculator service contract is used for communication between the WCF client and service. The WCF channel is configured with the system-provided WSHttpBinding. This contract was generated by using Add Service Reference in Visual Studio. It is essentially a copy of the contract that was defined in the GettingStartedLib project. The WSHttpBinding binding specifies HTTP as the transport, interoperable security, and other configuration details.
For more information about how to use the generated client with this configuration, see How to: Use a Client.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.