-1

我是 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 的新手。所以请详细指导我。谢谢。

4

1 回答 1

0

客户端配置中的大多数多余部分仅意味着已在某一时刻为客户端启用了 WCF 诊断。

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

于 2014-02-02T18:31:13.753 回答