Search code examples
wcfsilverlightstatic-variables

is it safe to use public static variables in WCF?


I'm reading emails in my Silverlight 4 app (VS2010, C#), I've created a WCF which handles email operations (through IMAP), and I consume its functions in my Silverlight app (in fact my Silverlight app is going to be a user control in another parent silverlight application). Can I declare public static variables for username, password, imap server address and other items? My application will have several users, so is it safe to use public static variables in my WCF or I should always pass username, password, imap address, port and other stuff to my WCF functions for each user? what are my options here?

should I use a mechanism such as sessions or I can safely use static variables? what would happen if several users call my service at the same time?

thanks


Solution

  • If those parameters are going to be same for all the users then in simple case you can read them from config file instead of hard-coding them in static variables. In that way if the server or port changes then you can easily update the web.config without going for a recompile.

    If those parameters changes from user to user then the better idea would be create a class in the service side that contains all those parameters.

    There is no any problem in using static variables in WCF when they are just constants. When they are not constants you may have to look into this thread.