• 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/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.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

  • 相关阅读:
    面试题八 二进制中 1 的个数
    面试题七 斐波那契数列
    面试题六 用两个栈实现队列
    第 3 章 第 2 题 求级数问题 递归法实现
    第 3 章 第 1 题 精简冗余 if 语句问题 使用数组实现
    第 2 章 第 10 题 测量电灯泡体积问题
    第 2 章 第 9 题 顺序 & 二分搜索效率分析问题
    带缓冲的IO( 标准IO库 )
    Linux 中权限控制实例
    Linux 中权限的再讨论( 下 )
  • 原文地址:https://www.cnblogs.com/MayGarden/p/1645200.html
Copyright © 2020-2023  润新知