WCF服务太忙了

时间:2011-11-08 12:47:47

标签: wcf c#-4.0 wcf-client

服务是否正常工作,但当数据库关闭时,应用程序池最终停止运行。

在服务方面,我们为连接到数据库的所有代码尝试/ catch with Fault Execeptions。

我正在寻找有关如何通过控制服务来减少这类错误的提示,因为我们无法控制服务器。

如果需要更多详细信息,请与我们联系,我们会更新帖子。

自定义客户端提供商:

   public class ClientWCFProvider<TT> : IDisposable
    {

            private ChannelFactory<TT> channel;

            public TT WCF { get; set; }

            public ClientWCFProvider(string service)
            {
                channel = GetServiceChannel(service);
                WCF = channel.CreateChannel();
            }

            private ChannelFactory<TT> GetServiceChannel(string service)
            {
                 BasicHttpBinding serviceBinding = new BasicHttpBinding();
                //set the config on the bindings for timeouts etc.
                serviceBinding.MaxReceivedMessageSize = 105190152; 
                serviceBinding.MaxBufferSize = Convert.ToInt32(serviceBinding.MaxReceivedMessageSize);
                serviceBinding.OpenTimeout = new TimeSpan(0, 3, 0);
                serviceBinding.SendTimeout = new TimeSpan(0, 3, 0);


                EnvironmentDescriptor serviceEnvironment;
                EndpointAddress ServiceEndpoint;

                ... code to setup the endpoint


                ServiceChannel = new ChannelFactory<TT>(serviceBinding, ServiceEndpoint);

                return ServiceChannel;
    }
    public void Dispose()
        {
            ((IClientChannel)WCF).Close();
            channel.Close();
        }
}

然后像这样调用服务:

using(var x = new ClientWCFProvider<TT>("NameOfService"))
{
...
}

1 个答案:

答案 0 :(得分:1)

基于ErnieL的最终解决方案是:http://blog.davidbarrett.net/archive/2007/11.aspx