WCF服务和客户端配置文件

时间:2014-02-02 18:27:43

标签: wcf wcf-configuration

我是wcf的新手所以经常从各个网站上阅读很多关于wcf的文章。最近我看到了一个wcf聊天代码,看到了服务端和客户端的配置代码差异。

是否必须提供服务端&客户端配置应该在配置设置方面看起来类似。

这里我粘贴了两个配置代码,告诉我为什么在服务和配置设置中有所不同?客户端?

服务端配置详细信息

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="ChatSvc.ChatService" behaviorConfiguration="ChatServiceBehavior">
                <endpoint address="net.tcp://localhost:8085/Chat" binding="netTcpBinding" 
                    contract="ChatSvc.IChat" />
                <!--bindingConfiguration="PortSharingBinding"-->

                <endpoint address="net.tcp://localhost:8085/Chat/mex"
                          binding="mexTcpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <!--<bindings>
            <netTcpBinding>
                <binding name="PortSharingBinding" portSharingEnabled="true">
                    <security mode="None"/>
                </binding>
            </netTcpBinding>
        </bindings>-->
        <behaviors>
            <serviceBehaviors>
                <behavior name="ChatServiceBehavior">
                    <serviceMetadata httpGetEnabled="false"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

客户端配置详细信息

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Off, ActivityTracing"
        propagateActivity="true">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="d:\cs\cs 4\cs 4-1\work\ChatApplication_FT - ChunkedBufferedFT\simpleclient\TracingFiles\app_tracelog.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelTraceListener" traceOutputOptions="Timestamp, Callstack">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false"
        logMessagesAtTransportLevel="false" />
    </diagnostics>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IChat" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
          transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="67108864"
          maxBufferSize="524288" maxConnections="100" maxReceivedMessageSize="524288">
          <readerQuotas maxDepth="32" maxStringContentLength="268435456"
            maxArrayLength="67108864" maxBytesPerRead="67108864" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="20:00:10"
            enabled="true" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
        <binding name="NetTcpBinding_IChat1" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
          maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="20:00:10"
            enabled="true" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:8085/Chat" binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_IChat" contract="ChatSvc.IChat"
        name="NetTcpBinding_IChat" />
    </client>
  </system.serviceModel>
</configuration>

现在我的问题是客户端有这么多设置,但服务端的设置很少.....怎么可能。服务是否正常运作?

我是wcf的新手。所以请详细指导我。感谢。

1 个答案:

答案 0 :(得分:0)

客户端配置中的大部分过剩意味着WCF诊断已经为客户端启用了一个点。

例如,客户端配置的整个<system.diagnostics>部分完全是可选的,可以删除。