我开发了一个 Silverlight 聊天应用程序。在一个窗口中同时加载多个聊天窗口,每个聊天窗口都会创建一个到 wcf 双工服务的新连接。但是在每 10 个聊天窗口之后,它就会与 wcf 断开连接并停止工作。我为节流选项编写了一些代码,但它们不起作用。这是我的代码:-
public class PollingDuplexServiceHostFactory : ServiceHostFactoryBase
{
public override ServiceHostBase CreateServiceHost(string constructorString,
Uri[] baseAddresses)
{
return new PollingDuplexSimplexServiceHost(baseAddresses);
}
}
/// <summary>
/// PollingDuplexServiceHostFactory
/// </summary>
class PollingDuplexSimplexServiceHost : ServiceHost
{
public PollingDuplexSimplexServiceHost(params System.Uri[] addresses)
{
InitializeDescription(typeof(JakayaChatService), new UriSchemeKeyedCollection(addresses));
Description.Behaviors.Add(new ServiceMetadataBehavior());
var throttle = Description.Behaviors.Find<ServiceThrottlingBehavior>();
if (throttle == null)
{
throttle = new ServiceThrottlingBehavior
{
MaxConcurrentCalls = 1000,
MaxConcurrentInstances = 1000,
MaxConcurrentSessions = 1000
};
Description.Behaviors.Add(throttle);
}
}
protected override void InitializeRuntime()
{
PollingDuplexBindingElement pdbe = new PollingDuplexBindingElement()
{
ServerPollTimeout = TimeSpan.FromSeconds(05),
InactivityTimeout = TimeSpan.FromSeconds(3600)
};
// Add an endpoint for the given service contract.
this.AddServiceEndpoint(
typeof(IJakayaChatService),
new CustomBinding(
pdbe,
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()),
"");
// Add a metadata endpoint.
this.AddServiceEndpoint(
typeof(IMetadataExchange),
MetadataExchangeBindings.CreateMexHttpBinding(),
"mex");
base.InitializeRuntime();
}
}