How to: Configure a Basic Windows Communication Foundation Client
2010-01-12 15:31
495 查看
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.
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.
[align=center][/align]<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator">
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
address="http://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: http://localhost:8000/ServiceModelSamples/service
The endpoint element specifies that the
For more information about how to use the generated client with this configuration, see How to: Use a Windows Communication Foundation Client.
[align=center][/align]Copy Code
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.
Getting Started Sample
Self-Host
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.
[align=center][/align]<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator">
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
address="http://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: http://localhost:8000/ServiceModelSamples/service
The endpoint element specifies that the
Microsoft.ServiceModel.Samples.ICalculatorcontract 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.[align=center][/align]Copy Code
<?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="http://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 ClientConcepts
Using Bindings to Configure Services and ClientsOther Resources
Service Metadata Utility (Svcutil.exe)Getting Started Sample
Self-Host
相关文章推荐
- How to: Create a Windows Communication Foundation Client
- How to: Use a Windows Communication Foundation Client
- How to: Host and Run a Basic Windows Communication Foundation Service
- How to: Host and Run a Basic Windows Communication Foundation Service
- How to: Implement a Windows Communication Foundation Service Contract
- How to: Define a Windows Communication Foundation Service Contract
- WCF (Windows Communication Foundation) Create & Implement a WCF Client
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- How to: Implement a Windows Communication Foundation Service Contract
- Windows Communication Foundation (WCF)和Windows CardSpace
- Windows Communication Foundation(WCF) 一步一步从入门到精通
- Windows Communication Foundation (WCF)和Windows CardSpace的示例程序
- Windows 通信基础(Windows Communication Foundation)
- Windows Communication Foundation入门(Part Two)
- Windows Communication Foundation 基础概念
- Windows Communication Foundation (WCF) 通道堆栈编码
- 什么是 Windows Communication Foundation
- Windows Workflow Foundation 与 Windows Communication Foundation 集成