最近在开发一个平台的子系统要用到WCF,WCF最麻烦的就是配置,所以有些配置先记下来,给以后自己用 <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="false" /> <!--是否在错误中包含有关异常的详细信息--> <serviceDebug includeExceptionDetailInFaults="True" /> <!-- 使用 ServiceThrottlingBehavior 类可控制各种吞吐量设置,这些设置可以让您优化服务性能,以帮助避免应用程序内存不足。 http://msdn.microsoft.com/zh-cn/library/system.servicemodel.description.servicethrottlingbehavior(v=vs.110).aspx MaxConcurrentCalls 属性可限制当前在整个 ServiceHost 中处理的消息数目。默认为处理器计数的 16 倍。 MaxConcurrentInstances 属性可限制在整个 ServiceHost 中一次执行的 InstanceContext 对象数。默认为 MaxConcurrentSessions 的值和 MaxConcurrentCalls 值的总和。 MaxConcurrentSessions 属性可限制 ServiceHost 对象可以接受的会话数。服务主机可接受的最大会话数。 默认为处理器计数的 100 倍。 因为运行时负载平衡需要运行应用程序的经验,所以,通过应用程序配置文件使用 ServiceThrottlingBehavior 是修改执行过程以获得最佳服务性能的最常用方法。 配置文件中使用 <serviceThrottling> 元素来设置此属性的值。 --> <serviceThrottling maxConcurrentCalls="10000" maxConcurrentInstances="20000" maxConcurrentSessions="10000" /> <dataContractSerializer maxItemsInObjectGraph="6553600"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="OGEMRAY.PCS.Handler.DIDUIDManager"> <endpoint address="net.tcp://192.168.2.135:8787/DIDUIDManager/" binding="customBinding" bindingConfiguration="MySessionBinding" contract="OGEMRAY.PCS.Handler.IDIDUIDManager"> </endpoint> <endpoint address="net.tcp://192.168.2.135:8788/DIDUIDManager/" binding="mexTcpBinding" contract="IMetadataExchange" /> </service> <service name="OGEMRAY.PCS.Handler.AccoutOnLine"> <endpoint address="net.tcp://192.168.2.135:8787/AccoutOnLine"/" binding="customBinding" bindingConfiguration="MySessionBinding" contract="OGEMRAY.PCS.Handler.IAccoutOnLine""> </endpoint> <endpoint address="net.tcp://192.168.2.135:8788/AccoutOnLine"/" binding="mexTcpBinding" contract="IMetadataExchange" /> </service> </services> <bindings> <customBinding> <!--WSHttpBindingBase 属性 http://msdn.microsoft.com/zh-cn/library/vstudio/System.ServiceModel.WSHttpBindingBase_properties(v=vs.100).aspx --> <binding name="MySessionBinding"> <!--transactionFlow 获取或设置一个值,该值指示此绑定是否应支持流动 WS-Transactions。 如果支持事务的流动,则为 true;否则为 false。默认值为 false。--> <transactionFlow /> <!--binaryMessageEncoding 定义一个在网络上以二进制形式对 Windows Communication Foundation (WCF) 消息进行编码的二进制消息编码器。 http://msdn.microsoft.com/zh-cn/library/ms731780(v=vs.110).aspx --> <binaryMessageEncoding /> <!--reliableSession 获取一个对象,当使用系统提供的一个绑定时,该对象可提供对可用的可靠会话绑定元素属性的便捷访问。 http://msdn.microsoft.com/zh-cn/library/System.ServiceModel.Channels.ReliableSessionBindingElement(v=vs.110).aspx maxPendingChannels 可靠会话期间可为挂起状态的最大通道数。可为挂起状态的最大通道数。 默认值为 4。 设置的值小于或等于零,或者大于 16384。 通道在等待被接受时处于挂起状态。 一旦达到该限制,就不会创建任何通道并将其置于挂起模式,直到此数值降低(通过接受挂起的通道)。 这是对每个侦听器的限制。当达到此阈值时如果远程应用程序尝试建立新的可靠会话,则会拒绝请求且打开操作将提示此错误。 --> <reliableSession maxPendingChannels="10000"/> <!--tcpTransport 定义通道用于传输自定义绑定消息的 TCP 传输。 http://msdn.microsoft.com/zh-cn/library/ms731366(v=vs.110).aspx listenBacklog 可为 Web 服务挂起的最大排队连接请求数。 connectionLeaseTimeout 属性限制客户端在引发连接异常之前将等待连接的持续时间。 这是一个套接字级别属性,控制可能为 Web 服务挂起的最大排队连接请求数。 ListenBacklog 太低时,WCF 将停止接受请求,并因此删除新连接,直到服务器承认一些现有队列连接。默认值为 16 * 处理器数。 maxPendingConnections 获取或设置此共享服务的最大挂起连接数,默认值为 100。 maxPendingAccepts 获取或设置共享服务侦听终结点上的最大未完成并发接受线程数。 默认值为 2。 --> <tcpTransport listenBacklog="10000" maxPendingConnections="10000" maxPendingAccepts="10000" /> </binding> </customBinding> </bindings> </system.serviceModel>