am sorry if this question will be a bit to broad but if this is question about normal ASP.NET MVC 5 Owin based application with default connection to MSSQL server i would not have such hard time but we use CRM as our database.
Ok as i mention am working on ASP.NET MVC5 application and am having hard time finding what is the best practice to create, keep open and to close connection to Dynamics CRM 365?
I found some many posts and blogs but everyone pulling on his side of the road.
Some say it's better for every request to open new connection in using
statement so it could be closed right away (that's sounds good but it's a possible that requests will be slow because on every request it needs to open new connection to CRM).
Some say it' better to make singleton
object on application scope, keep it open during application lifetime and reuse it on every request.
Normally i would use OrganizationServiceProxy
in some simple console app but in this case am not sure should i use OrganizationServiceProxy
or CrmServiceClient
or something else?
If anyone have or had some similar problem, any hint would be great.
UPDATE:
@Nicknow
I downloaded SDK from SDK 365 and am using this dll-s.
Microsoft.Xrm.Sdk.dll
, Microsoft.Crm.Sdk.Proxy.dll
, Microsoft.Xrm.Tooling.Connector.dll
and Microsoft.IdentityModel.Clients.ActiveDirectory.dll
.
You mention
Microsoft.CrmSdk.XrmTooling.CoreAssembly 8.2.0.5.
if am correct this nuget package use official assembly that i downloaded, or there are some modification to this package?
About that test
proof test
if i got it right, no matter if i use using
statement, implement Dispose()
method or just use static class on application scope for a lifetime of application i will allways get same instance (If i use default settings RequireNewInstance=false
)?
For code simplicity, I usually create a static class (a singleton could be used too, but would usually be overkill) to return a CrmServiceClient object. That way my code is not littered with new CrmServiceClient calls should I want to change anything about how the connection is being made.
So it would be good practice to create static class on application scope that lives for application lifetime? That means that every user that makes request would use same instance ? Wouldn't that be i performance issue for that one connection?
All of your method calls will execute to completion or throw an exception thus even if the GC takes a while there is no open connection sitting out there eating up resources and/or blocking other activity.
This one takes me back to section where i allways get same instance of CrmServiceClient
and got the part that xrm.tooling handles cached connection o the other side but what happens on this side (web application).
Isn't the connection to CRM (i.e. CrmServiceClient
) unmanaged resources, shouldn't i Dispose()
it explicitly?
I found some examples with CrmServiceClient
and pretty much in all examples CrmServiceClient
is casted in IOrganizationService
using CrmServiceClient.OrganizationWebProxyClient
or CrmServiceClient.OrganizationServiceProxy
.
Why is that and what are the benefits of that?
I got so many questions but this is already allot to ask, is there any online documentation that you could point me to it?