我如何运行WCF服务的构造函数一次对所有客户端时,它的InstanceContextMode设置为PerSession? [英] How can I run a WCF service constructor once for all clients when it's InstanceContextMode is set to PerSession?

查看:212
本文介绍了我如何运行WCF服务的构造函数一次对所有客户端时,它的InstanceContextMode设置为PerSession?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何运行code在WCF服务的构造函数只有一次当的 ServiceBehaviorAttribute.InstanceContextMode 设置为 PerSession

How can I run the code in the constructor of a WCF Service only once when the ServiceBehaviorAttribute.InstanceContextMode is set to PerSession?

[ServiceBehavior(
    InstanceContextMode = InstanceContextMode.PerSession, 
    ConcurrencyMode = ConcurrencyMode.Single)]
public class SomeService : ISomeService
{
    public SomeService()
    {
        this.RunThisOnceForAllClients();
    }

    private void RunThisOnceForAllClients() { }
}

或者,我怎么能在运行后自动WCF服务的方法运行,但它的只是将所有客户端上运行,一旦调用

请帮忙。先谢谢了。

我用href="http://msdn.microsoft.com/en-us/library/ms733069.aspx" rel="nofollow">托管Windows服务一个如果你想知道为什么我需要像这样做,我需要执行的上传将上传数据库的方法该服务到另一个服务的,但它会在一定时间内执行的,所以我把它在将总是只要服务正在运行运行另一个线程。

I deploy my WCF Service using a Managed Windows Service. My code is in C#. Framework is in .NET 4. Project is build in Visual Stuido 2010 Professional. The service is consumed by a Windows Forms Application. In case you wonder on why do I need to do it like this, I need to execute an Uploader method that will upload the database of the service to another service, but it will be executed in a certain time so I put it in another thread that will always run as long as the service is running.

推荐答案

为什么不执行此操作,在Windows服务承载WCF服务之前,因此它可以准备好,一旦WCF服务上线。您可以从运行不可能得到自己完成线程的事件,然后部署WCF服务。

Why not run this operation just before you host the WCF Service in your windows service so it can be ready as soon as the WCF Service goes online. You can get from the running thread an event that it is finished and then deploy the WCF Service.

这篇关于我如何运行WCF服务的构造函数一次对所有客户端时,它的InstanceContextMode设置为PerSession?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆