locked
CRM 2015 - Portal RRS feed

  • Question

  • Hi All,

    I write an MVC application that connets the CRM . I am caching the service into memory cache in WCF service.. When concurrent users are trying to log into system crm service gives can not access disposed object error.  Here is the code below.

    Any Ideas?

     using (OrganizationServiceProxy proxy = new OrganizationServiceProxy(new Uri(OrganizationUrl), null, userCredentials, null))
                            {
                                proxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                                //create organization service with layer of proxy
    
                                service = (IOrganizationService)proxy;
                            }


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog

    Wednesday, September 9, 2015 4:01 PM

Answers

  • Hello,

    I believe that error occurs because you use 'using'. I'm not a .Net guru but I know that 'using' is used for usage of class instance only in 'using' block and after code leaves block instance is disposed - https://msdn.microsoft.com/en-us/library/yh598w02.aspx

    So in case you want to cache connection object and not recreate it every time - just implement Singleton pattern.


    Dynamics CRM MVP
    My blog

    Wednesday, September 9, 2015 5:48 PM
    Moderator

All replies

  • Hello,

    I believe that error occurs because you use 'using'. I'm not a .Net guru but I know that 'using' is used for usage of class instance only in 'using' block and after code leaves block instance is disposed - https://msdn.microsoft.com/en-us/library/yh598w02.aspx

    So in case you want to cache connection object and not recreate it every time - just implement Singleton pattern.


    Dynamics CRM MVP
    My blog

    Wednesday, September 9, 2015 5:48 PM
    Moderator
  • Hi Andrii

    Your post is very helpfull. Singleton is the solution that ı am looking for..


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog

    Wednesday, September 9, 2015 11:29 PM