How to: Configure a Basic Windows Communication Foundation Client

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

  1. 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.

  2. 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="http://localhost:8000/ Servic eModelSampl es/Service/ Calcul atorService"
               binding="wsHttpBinding"
               bindingConfiguration="WSHttpBinding_ICalculator"
               contract="Microsoft. Servic eModel.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.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.

  3. 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="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

转载于:https://www.cnblogs.com/MayGarden/archive/2010/01/12/1645200.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值