六、框架的应用服务器配置
应用服务器的配置有几个部分,首先确认应用服务器是否担任了数据服务器角色,如果是,需要配置数据库访问信息:
<config>
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"/>
<add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
<add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="connection.connection_string" value="Data Source=.;Initial Catalog=DataBaseName;UID=sa;Password="/>
<add key="adonet.batch_size" value="50"/>
<add key="cache.provider_class" value="NHibernate.Caches.MemCache.MemCacheProvider,NHibernate.Caches.MemCache"/>
<add key="cache.use_second_level_cache" value="true"/>
<add key="cache.use_query_cache" value="true"/>
<add key="cache.default_expiration" value="300"/>
<add key="default_expiration" value="300"/>
<add key="expiration" value="300"/>
</config>
</activerecord>
如果启用了二级缓存,使用memcached服务器,配置如下:
<memcache>
<memcached host="127.0.0.1" port="11211" weight="2" />
<memcached host="192.168.1.2" port="11211" weight="2" />
</memcache>
数据访问服务器的通信配置:
<system.serviceModel>
<services>
<service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
<!-- -->
<endpoint address="http://127.0.0.1:8000/" contract="Csla.Server.Hosts.IWcfPortal" binding="customBinding" bindingConfiguration="compactBinding"/>
<endpoint address="net.tcp://127.0.0.1:5898" contract="Csla.Server.Hosts.IWcfPortal" binding="netTcpBinding" bindingConfiguration="WcfPortalBinding"/>
</service>
</services>
<bindings>
<customBinding>
<binding name="compactBinding" sendTimeout="00:10:00">
<compactMessageEncoding>
<binaryMessageEncoding>
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binaryMessageEncoding>
</compactMessageEncoding>
<httpTransport maxReceivedMessageSize="2147483647"/>
</binding>
</customBinding>
<netTcpBinding>
<!-- -->
<binding name="WcfPortalBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:01:00" sendTimeout="00:01:00">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binding>
</netTcpBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="compactMessageEncoding" type="Amib.WCF.CompactMessageEncodingElement, CompactMessageEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bindingElementExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
期中,HTTP启用了压缩支持。
如果服务器没有担任数据服务器的角色,只作为应用服务器使用,通信配置如下:
<appSettings>
<add key="CslaAuthentication" value="Csla" />
<add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla"/>
</appSettings>
<system.serviceModel>
<client>
<endpoint name="WcfDataPortal" address="http://localhost:8000/" binding="customBinding" bindingConfiguration="compactBinding" contract="Csla.Server.Hosts.IWcfPortal" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceCertificate">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="compactBinding" sendTimeout="00:10:00">
<compactMessageEncoding>
<binaryMessageEncoding>
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
</compactMessageEncoding>
<httpTransport maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="compactMessageEncoding" type="Amib.WCF.CompactMessageEncodingElement, CompactMessageEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
</system.serviceModel>
应用服务器如果启用日志记录,配置如下:
<common>
<logging>
<!--
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
<arg key="configType" value="INLINE" />
<arg key="level" value="INFO" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy-MM-dd HH:mm:ss:fff" />
</factoryAdapter>
-->
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="DEBUG" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy-MM-dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="App_Data/log/" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="5MB" />
<param name="RollingStyle" value="Date" />
<!--Size ==- Date-->
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value="yyyy-MM-dd.'log'" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<!--
-->
<appender-ref ref="RollingLogFileAppender" />
</root>
<logger name="NHibernate">
<level value="WARN"/>
<!--
<appender-ref ref="RollingLogFileAppender" /> -->
</logger>
<logger name="NHibernate.SQL" >
<level value="WARN"/>
<!--
<appender-ref ref="RollingLogFileAppender" /> -->
</logger>
<logger name="Memcached.ClientLibrary.MemcachedClient">
<level value="WARN"/>
<!--
<appender-ref ref="RollingLogFileAppender" /> -->
</logger>
</log4net>
配置后的应用服务器: