WCF 服务太忙

发布于 2024-12-14 04:42:46 字数 1631 浏览 1 评论 0原文

服务是否正在工作,但是当数据库出现故障时,应用程序池最终会停止。

在服务方面,我们对连接到数据库的所有代码都进行了尝试/捕获错误异常。

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

如果需要更多详细信息,请告诉我,我将更新帖子。

自定义客户端提供程序:

   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"))
{
...
}

Are services are working, but when the Database goes down, the application pool ends up stopping.

On the service side, we have try/catch with Fault Execeptions for all code connecting to the databases.

I'm looking for an tips on how to reduce these type of errors from the control of the services, as we do not have control over the servers.

Please let me know if more details are needed, and I'll update the posting.

Custom Client-Side Provider:

   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();
        }
}

Then the services are called like this:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2024-12-21 04:42:46

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

The end solution, based on ErnieL is this: http://blog.davidbarrett.net/archive/2007/11.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文