zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    疑似CPU或者内存故障导致进程崩溃
    free如何知道释放内存长度:vs与glibc分配内存时编译器内部处理
    stun简介
    H264(NAL简介与I帧判断)
    H264码率设置
    简单的makefile模板
    ffmpeg显示视频
    一些yuv视频下载地址
    转载:P2P技术原理及应用(2)
    转载:P2P技术原理及应用(1)
  • 原文地址:https://www.cnblogs.com/MayGarden/p/1645200.html
Copyright © 2011-2022 走看看