Do you know when to use the different WCF Context Modes?


Let's talk about WCF's InstanceContextMode, give a brief overview of the possible values and determine when to use them.

InstanceContextMode is a property on the ServiceBehaviorAttribute class in .NET Framework 4.5. A developer will use the InstanceContextMode property to specify when new service objects are created.

Because the service object is not directly connected to the communicating channel, the lifetime of the service objects is independent of the lifetime of the channel between a client and the service application. The default value, PerSession, instructs the service application to create a new service object when a new communication session is established between a client and the service application. Subsequent calls in the same session are handled by the same object.

There are 3 context modes in WCF:

  1. PerCall
  2. PerSession (Default)
  3. Single

The default value, PerSession, instructs the service application to create a new service object when a new communication session is established between a client and the service application. Subsequent calls in the same session are handled by the same object. PerSession indicates that each service object handles requests from one client channel. A service configured for private sessions cannot typically support more than a few dozen (or perhaps up to a few hundred) outstanding clients due to the cost associated with each such dedicated service instance.

PerCall creates a new InstanceContext object prior to and recycled subsequent to each call. If the channel does not create a session this value behaves as if it were PerCall. After the method call returns, if the object implements IDisposable, then Windows Communication Foundation calls IDisposable.Dispose on it.

Single creates only one InstanceContext object. It is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created. The singleton service is the ultimate shareable service. When a service is configured as a singleton, all clients get connected to the same single well-known instance independently of each other, regardless of which endpoint of the service they connect to. The singleton service lives forever, and is only disposed of once the host shuts down. The singleton is created exactly once when the host is created.

Which instance context mode to use and when

Per session (Default)

• When you want to maintain states between WCF calls.
• When you don't have very many concurrent connections and don't need to scale up.
• When you have light resource references

Per call

• When you want a stateless services
• When your service holds intensive resources like connection and huge memory objects.
• When scalability is a prime requirement.
• When your WCF functions are called in a single threaded model.

Single

• When you want share global data through your WCF service.
• When scalability is not a concern.



66 comments:

  1. Thank you for this detailed article on Web design training. I’m aspiring to do Web design training.

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.

      Dot Net Training in Chennai Dot Net Training in Chennai .Net Online Training .Net Online Training Dot Net Training in Chennai Dot Net Training in Chennai


      Dot Net Online Training Dot Net Online Training LINQ Online Training LINQ Online Training ASP.NET Online Training ASP.NET Online Training

      Delete
  2. Thank you for this valuable information. It was really helpful.

    IOSH safety course in Kuwait

    ReplyDelete
  3. This is really an awesome article. Thank you for sharing this.It is worth reading for everyone. Visit us:
    Oracle Training in Chennai

    ReplyDelete
  4. great article!!!!!This is very importent information for us.I like all content and information.I have read it.You know more about this please visit again.
    Oracle RAC Training in Chennai

    ReplyDelete
  5. Wonderful tips, very helpful well explained. Your post is definitely incredible. I will refer this to my friend.
    SalesForce Training in Chennai

    ReplyDelete
  6. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    Java Training in Chennai

    ReplyDelete
  7. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    PHP Training in Chennai

    ReplyDelete
  8. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for me..
    Android Training in Chennai

    ReplyDelete
  9. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    SAP Training in Chennai

    ReplyDelete
  10. Excellent information with unique content and it is very useful to know about the information based on blogs.
    Hadoop Training in Chennai

    ReplyDelete
  11. Excellent information with unique content and it is very useful to know about the information based on blogs.
    Hadoop Training In Chennai | oracle apps financials Training In Chennai | advanced plsql Training In Chennai

    ReplyDelete
  12. Good article with excellent idea! I appreciate your post.Regards Sarkari Result

    ReplyDelete
  13. It’s really a nice and helpful piece of information. I’m glad that you shared this helpful info with us. Please keep us informed like this.
    Employment News in India

    ReplyDelete
  14. Thank you for explaining to us as to when to use this mode. It was really helpful.

    jewelry photo editing services

    ReplyDelete
  15. Interesting blog to know about WCF Modes.Thanks for the blog.Please keep updating us.

    Hadoop training in chennai

    ReplyDelete
  16. I got a good idea when to use WCF and i hope it should be useful all .Net experts. We are providing Dot Net Training in Chennai at IICT. I hope we are giving training in all the concepts you can check our IICT Reviews as well.

    ReplyDelete
  17. This is really a great post. Thank you for taking time to provide us some of the useful and exclusive information with us. Keep on blogging!!

    Salesforce Training in Chennai

    ReplyDelete
  18. These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post. Your articles really impressed for me,because of all information so nice.

    Selenium training in adyar

    ReplyDelete
  19. I Have Been wondering about this issue, so thanks for posting.
    vigrx plus

    ReplyDelete

  20. I feel happy about and I love learning more about this topic. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with in me. Thanks for sharing article like this.

    informatica training in Mylapore

    ReplyDelete
  21. Well, I read this information first time in your blog. That was a great research, it really nice and amazing one dear.Contact Us Content

    ReplyDelete
  22. The Information which you provided is very much useful for us. Thank You for Sharing Valuable Information. QTP Training in Chennai | Software Testing Training in Chennai

    ReplyDelete
  23. Everyone loves it when individuals come together and share thoughts. Great blog, continue the good work!
    salesforce training in hyderabad

    ReplyDelete
  24. Awesome Blog.Informative Post.Thanks for sharing the information.
    Incor One City Hyderabad

    ReplyDelete
  25. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Hadoop Training in Chennai | Hadoop Training Chennai

    ReplyDelete
  26. Good article with excellent idea! I appreciate your post
    unix training in chennai

    ReplyDelete
  27. Thank you for explaining to us as to when to use this mode. It was really helpful.
    ios training in chennai

    ReplyDelete
  28. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Dot net training in Chennai | dot net course in Chennai

    ReplyDelete
  29. Its really helpfull.., thanks for sharing this.

    Papa jobs Providing latest information about Current affairs, Bank Recruitment, Government jobs, Bank jobs, IT jobs., check this link papa jobs i hope this is very use full to you and all the very best Guys.

    ReplyDelete
  30. Nice information for job seekers. Thanks for sharing the awesome information , i also recommend online Notification

    ReplyDelete
  31. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  32. watch series At Watch Series Database You Can Watch Series Online for free, The Website Is Updated On Daily Basis With New Tv Shows Episodes.

    ReplyDelete
  33. This comment has been removed by the author.

    ReplyDelete
  34. Judi Bola Online Terbesar dan Terpercaya di Indonesia, Agen Bola Terbaik, Agen Casino Online, Agen Judi Poker Online.
    bandar judi

    ReplyDelete
  35. MICKEY MOUSE Male Extra pills are famous on the market. But you have to know some side effects and results. My prof review will help you.

    ReplyDelete
  36. This comment has been removed by the author.

    ReplyDelete
  37. The blog gave me idea to use WCF thanks for sharing it
    Hadoop Training in Chennai

    ReplyDelete
  38. Penomet Penis Pump Review - A detailed and honest review with pictures, personal experiences and product information.
    best penis pumps

    ReplyDelete
  39. Looking to find out if Hair Loss Protocol's natural ingredients can help? ... whether or not there's sufficient clinical evidence showing they can help regrow hair.
    http://fitlivings.com/regrow-hair-protocol-review/

    ReplyDelete

  40. This article is so informatic and it really helped me to know more about the Selenium Testing. So keep updating the content regularly.
    Selenium Training in Chennai | Selenium Training | Selenium Course in Chennai

    ReplyDelete
  41. hi welcome to this blog. really you have post an informative blog. it will be really helpful to many peoples. thank you for sharing this blog.
    android training in chennai

    ReplyDelete
  42. Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long.

    https://en.gravatar.com/marinemuscle
    https://medium.com/@jamicarpuenter
    http://www.purevolume.com/listeners/Jamipuent

    ReplyDelete
  43. Nice one, very impressive and more informative article, thanks for sharing your valuable info and time, it is very easy to learn and understand by me.
    Java Training institute in chennai |Java Training institute in velachery

    ReplyDelete
  44. Nice to read your ideas, thanks for sharing wonderful ideas and article, keep rocks....
    PHP Training in velachery | PHP Training institute in velachery

    ReplyDelete
  45. i read this article once again as well, it is Good and nice information, thanks for sharing your views and ideas.. keep rocks and updating..

    Software Testing Training in chennai |
    PHP Training in chennai

    ReplyDelete
  46. Thank you for posting this beneficial content material, accurate to recognise about new matters right here, permit me percentage this,  seo training in chennai

    ReplyDelete
  47. There are so many useful information in your post, I like it all the time. And I want to share this boost app ranking with you, you can take a look. This is very useful.

    ReplyDelete
  48. male extra pills are famous on the market. But you have to know some side effects and results. My prof review will help you.

    ReplyDelete
  49. Before the Jes Extender was available in Australia, the only legal and medically approved option to enlarge the penis was by having surgery.
    The SizeGenetics Best Penile Extender is my number 1 choice for the best extender right now! Look what other men say about PeniMaster, Euroextender, SizeGenetics, Jelq Device and others. why pass up on that chance?
    Penis Enlarger exercises consist of a series of massages and stretches that naturally promote penis growth. The flaccid size is irrelevant, some men have a rather small penis growing to enormous size when erect,

    ReplyDelete
  50. Muscle supplements brand produces hardcore Military Grade legal steroid alternatives so strong that they're ONLY legal in USA! Our review reveals their ingredients, stacks, side effects and their ability to improve bodybuilding cycles.
    devil dog gym
    dog steroids for muscle
    Marine Muscle
    Legal Steroids
    legal steroids for sale
    legal steroid
    buy legal steroids
    best legal steroid
    steroids for muscle gain

    ReplyDelete
  51. What is VigRX Oil? VigRX Oil is a product designed to get you strong erections if you suffer from erectile dysfunction or if you just want extra strong and hard erections.
    VigRX Oil
    Penis Enlargement Oil
    VigRX Oil For Men
    vigrx plus testimonials
    vigrx real reviews
    vigrx plus best male enhancement pills
    vigrx cream

    ReplyDelete
  52. ProSolution Gel is a male performance enhancement lubricant. This gel boosts nitric oxide levels the moment it is applied. ProSolution gel sounds really good – right? A gel that can rid you of all those sexual performance problems you'd rather bury in the back of your mind and forget.
    male enhancement reviews
    male enhancement lubricant
    male performance enhancer
    pro solution gel
    Prosolution Gel
    dick pump
    penis pump before and after
    Buy Prosolution Gel
    penis pump results
    male enhancement gel reviews

    ReplyDelete
  53. ProSolution Gel is a male performance enhancement lubricant. This gel boosts nitric oxide levels the moment it is applied. ProSolution gel sounds really good – right? A gel that can rid you of all those sexual performance problems you'd rather bury in the back of your mind and forget.
    male enhancement reviews
    male enhancement lubricant
    male performance enhancer
    pro solution gel
    Prosolution Gel
    dick pump
    penis pump before and after
    Buy Prosolution Gel
    penis pump results
    male enhancement gel reviews

    ReplyDelete
  54. Thank you for offering such a unique information really helpful for learners one of the recommended blog... Selenium Training institutes in Chennai | Oracle Training in Chennai

    ReplyDelete
  55. Than simply being fit in seeking after this objectives Ph375 we are prepared to find a way to keep up that fake looks or constitution.
    Ph.375
    Ph375
    Weight Loss
    Fat Burner
    Ph375 Review
    Ph375 Pills

    ReplyDelete
  56. Noocube is for people who want to keep up on the latest breakthroughs in brain health and optimization and the related areas of neuroscience.

    ReplyDelete