什么时候启动wcf服务 [英] when, how a wcf service is start

查看:320
本文介绍了什么时候启动wcf服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是wcf的新手,我想在服务启动时从字典中加载一些数据.
我应该在哪里放置加载数据功能?

我的意思是所有的WCF服务.包括自托管,IIS托管等.
谁能告诉我有关wcf服务的启动或有关此事的相关资源?

Hi All,

I am new at wcf, and I want to load some data from a dictionary when the service start.
where should I place the loading data function ?

I mean all kind of wcf service. includes self hosting ,IIS host and others.
Could anyone tell me about the starting of wcf service or related source about that matter?

Thank you very much in advance!

推荐答案

您可以查看^ ],然后查看有关静态构造函数的答复

或者,您可以仅在需要时加载数据,可以具有IfLoaded标志,然后通过这种方式,您只需在首次访问数据时加载一次数据(如果您正在尝试实现这种目的)
You could check out this post[^] and look at the reply regarding the static constructor

Alternatively, you could just load the data when you need it, you can have an IfLoaded flag and then that way you only need to load the data once when it is first accessed (if that is the kind of thing you are trying to achieve)


WCF服务没有像Windows服务或Windows应用程序那样启动. WCF服务仅由一个类组成,该类的方法由服务主机调用以进行处理.如果您需要实例化服务中的任何内容,我认为您需要为服务类创建一个构造函数并在那里实例化(我从未做过,所以不知道这是否被认为是一种好习惯).

我刚刚进行了一些研究,发现您可以创建一个静态构造函数,该构造函数仅在首次使用该类时才被调用,就像这样

A WCF service is not started as such like a windows service or a windows application. A WCF service merely consists of a class, whose methods are called by the service host to do stuff. If you need to instantiate anything in a service, I would think that you would need to create a constructor for your service class and do the instantiating there(I have never done this, so do not know if this would be considered good practice).

I have just done some research and found that you can create a static constructor that only gets called the first time the class is used, something like this

public class MyService : IMyService
   {
       //standard constructor
       public MyService()
       { }
       //Static constructor
       static MyService()
       { }
   }



这样,您需要事先完成的工作将只完成一次. [\ Edit]


希望对您有所帮助



that way the stuff you need to do beforehand will only get done once. [\Edit]


Hope this helps


静态构造函数有效,谢谢!
the Static constructor is worked, thank you guys!


这篇关于什么时候启动wcf服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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