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) service and a client that can call the service. For an overview of all six of the tasks, see the Getting Started Tutorial topic.
This topic adds the client configuration file that was generated using the Service Model Metadata Utility (Svcutil.exe) to the client project and explains the contents of the client configuration elements. 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.
The content of the configuration files generated for the client is provided in the example after the procedure.
To configure a Windows Communication Foundation client
Add the App.config configuration file generated in the previous How to: Create a Windows Communication Foundation Client procedure to the client project in Visual Studio. Right-click the client project in Solution Explorer, select Add and then Existing Item. Next select the App.config configuration file from the C:\Users\<user name>\Documents\Visual Studio 2005\Projects\Service\Client directory. (This is named the App.config file because you used the /config:app.config switch when generating this with Svcutil.exe tool.) Click OK. By default. the Add Existing Item dialog box filters out all files with a .config extension. To see these files select All Files (*.*) from the drop-down list box in the lower right corner of the Add Existing Item dialog box.
Open the generated configuration file. Svcutil.exe generates values for every setting on the binding. The following example is a view of the generated configuration file. Under the <system.serviceModel> section, find the <endpoint> element. The following configuration file is a simplified version of the file generated.
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_ICalculator"> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="https://localhost:8000/ServiceModelSamples/Service/CalculatorService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator" contract="Microsoft.ServiceModel.Samples.ICalculator" name="WSHttpBinding_ICalculator"> </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: https://localhost:8000/ServiceModelSamples/service
The endpoint element specifies that the
Microsoft.ServiceModel.Samples.ICalculator
contract is used for the communication, which is configured with the system-provided WsHttpBinding. This 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 Windows Communication Foundation Client.
Example
The example shows the content of the configuration files generated for the client.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
bypassProxyOnLocal="false"
transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text"
textEncoding="utf-8"
useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true"
algorithmSuite="Default"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:8000/ServiceModelSamples/Service/CalculatorService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ICalculator"
contract="ICalculator"
name="WSHttpBinding_ICalculator">
<identity>
<userPrincipalName value="user@contoso.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Now the client has been configured. Proceed to How to: Use a Windows Communication Foundation Client. For troubleshooting information, see Troubleshooting the Getting Started Tutorial.
See Also
Tasks
How to: Create a Windows Communication Foundation Client
Concepts
Using Bindings to Configure Services and Clients
Other Resources
Service Metadata Utility (Svcutil.exe)
Getting Started Sample
Self-Host
© 2007 Microsoft Corporation. All rights reserved.
Build Date: 2009-08-07