Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted
Updated 28-Jun-11 23:25pm
v3
Comments
Pete O'Hanlon 29-Jun-11 5:22am    
What service? Are you self hosting the service or using IIS to host it? Without this information, it's impossible to give a definitive answer.

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)
 
Share this answer
 
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).

[Edit] 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

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


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


Hope this helps
 
Share this answer
 
v2
Comments
[no name] 29-Jun-11 9:00am    
Perfect Point. My 5 too.
Wayne Gaylard 29-Jun-11 9:10am    
Thnaks!
[no name] 29-Jun-11 23:53pm    
It's my Pleasure.
the Static constructor is worked, thank you guys!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900