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 disuccess the client configuration file that was generated using the Add Service Reference functionality of Visual Studio 2012 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.
To 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="email@example.com" /> </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: http://localhost:8000/ServiceModelSamples/Service/CalculatorService
The endpoint element specifies that the
ServiceReference1.ICalculatorservice contract is used for communication between the WCF client and service. The WCF channel is configured with the system-provided <
xref:System.ServiceModel.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 <
xref:System.ServiceModel.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.