SBX - Search With Button

SBX - Forum Post Title

Issue while creating concurrent instances of IOrganizationService service

Microsoft Dynamics CRM Forum

Jayakumar asked a question on 2 Jun 2016 10:31 PM
My Badges

Question Status

Suggested Answer

Hi,

We are having a performance issue in our CRM 2011 due to no of concurrent instances created for IOrganizationService service.

We have CRM 2011 installed with IFD ADFS configuration. There are around 100 users using the CRM application.

Our client will organize and manage Events in CRM.

We have a separate web portal for allowing public users to register for the events in CRM. Its a ASP.NET web application with forms authentication. The portal will create an instance of IOrganizationService and retrieve the events from CRM and display in the portal. Then the user will select some events and click the submit to register for the events. the registration is recorded in CRM. So all the retrieve, cerate, update is happening through IOrganizationService instance.

Now the problem is when the no if users using the portal is high the portal becomes very slow or even sometimes throw an error when creating an instance for IOrganizationService. It throws error as "Metadata contains a reference that cannot be resolved". This happens only when the no of users using the portal is very high. This also affects the CRM application performance.

Please advice on how to proceed with this issue. I knew IOrganizationService is not thread safe so for each update, create, delete new instance is created for a single session. So for 5000 users there will be 20,000 instances of IOrganizationService created approximately. Is this the correct way to handle the IOrganizationService. Is there any limit for the no of instances for IOrganizationService. As I said after certain limit the application throws error while initiating the IOrganizationService object. The application is accessible intermittently. Please help of how to resolve the issue.

Reply
Suggested Answer

Hi - the Xrm.Client library is designed for portals and uses connection pooling for performance - see my blog series - develop1.net/.../MicrosoftXrmClient-Part-1.aspx

Hope this answers your question?

Reply
Jayakumar responded on 8 Jun 2016 4:09 AM
My Badges

Hi Scott,

We are using this method to create instance of Organization Service. How to use connection pool here.

----Code----

Uri OrganizationURI = new Uri(ConfigurationManager.AppSettings["OrganizationUri"]);

string publicCode = ConfigurationManager.AppSettings["Code"];

string Username = ConfigurationManager.AppSettings.Get("UserName");

string Password = ConfigurationManager.AppSettings.Get("Password");

string Domain = ConfigurationManager.AppSettings.Get("Domain");

ClientCredentials _Credential = new ClientCredentials();

_Credential.UserName.UserName = Username + "@" + Domain;

_Credential.UserName.Password = Password;

using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(OrganizationURI, null, _Credential, _Credential))

{

// This statement is required to enable early-bound type support.

_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

_service = (IOrganizationService)_serviceProxy;

}

return _service;

Reply
Suggested Answer

You can't connection pool using the OrganizationServiceProxy - you need to use the Microsoft.Xrm.Client library

using (OrganizationService proxy = new OrganizationService(CrmConnection.Parse(connectionString)))

{

Reply
Jayakumar responded on 18 Jun 2016 11:24 AM
My Badges

Hi Scott,

This worked for  me.

static CrmConnection crmConnect = CrmConnection.Parse(@"ServiceUri=https://CRMHost;Username=crmuser;Password=password;");

crmConnect.ProxyTypesEnabled = true;

crmConnect.Timeout = new TimeSpan(0, 0, 60, 0);

OrganizationService orgService = new OrganizationService(crmConnect);

return orgService;

Thanks.

Jayakumar

Reply
Jayakumar responded on 18 Jun 2016 11:53 AM
My Badges

Hi Scott,

Since my portal is open to public users many users will be using parallel. To achieve the scalability how should I inititate the CRM connection. Do I need to initiate the CRMConnection as static so that the connection is initiated only once and shared for all users to create instance of OrganizationService.

1. Declare CrmConnection as static and initiate once for the app domain.

2. New instance of OrganizationService will be created for each operation but will use the Shared CrmConnection to create instance.

Is this correct or do I need to create a new CrmConnection for each user logged into our portal?

Thanks.

Jayakumar

Reply
Suggested Answer

Hi - the Xrm.Client library is designed for portals and uses connection pooling for performance - see my blog series - develop1.net/.../MicrosoftXrmClient-Part-1.aspx

Hope this answers your question?

Reply
Suggested Answer

You can't connection pool using the OrganizationServiceProxy - you need to use the Microsoft.Xrm.Client library

using (OrganizationService proxy = new OrganizationService(CrmConnection.Parse(connectionString)))

{

Reply

SBX - Two Col Forum

SBX - Migrated JS