We're creating an ASP.NET MVC app that talks to CRM 2011. We are using the Xrm.Client.Services.OrganizationService. We have a singleton pattern in place for this.
Under load we are seeing an ObjectDisposedException (cannot access a disposed object). I'm thinking that a singleton is not the way to go here.
I'm considering a [ThreadStatic] singleton, or a pool of services, or anything else that might help. Is anyone aware of any limits on the number of connections to CRM that can be made? Anyone experienced the disposed service before? I've been told that having too many org services connecting to CRM at once can be problematic as well, so that's why I'm not creating a new one for each hit to CRM.
Thanks for any help you can provide! If any more clarification is required, please ask.
The OrganizationService is not multi-thread safe. It is also user aware, so depending on how you've implemented the creation of the service, you may or may not be able to share it among users. (If you aren't impersonating it, you should be fine, but then you lose out on all of the integrated CRM security)
At one point in time I did write a CRM OrganizationService Pool, but it really wasn't any different then creating a service when needed. Ideally you'll probably only want to create a service once per request of a user.