We are developing a system that connects to Microsoft Dynamics CRM
using XRM SDK
, It’s server side is built on .NET MVC
, Front End Side is built upon Angularjs
We are facing a latency problem in API responses, ex. Login API needs at least 1.8 seconds to retrieve success or false response, and this API is the fastest one.
Other APIs are even slower, we tried to catch the source of this slowness in order to fix it, but no luck. is it XRM SDK
, API’s or CRM
itself.
If you can help .
var cols = new ColumnSet("exdyn_employeecontractid", "exdyn_contractstatus");
var secondEntityCols = new ColumnSet("exdyn_companyagreementid", "exdyn_agreementstatus");
var filter = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "exdyn_employeeid",
Operator = ConditionOperator.Equal,
Values = {model.EmployeeId}
},
new ConditionExpression
{
AttributeName = "exdyn_contractstatus",
Operator = ConditionOperator.Equal,
Values = { 3 } // approved {2} signed
},
},
FilterOperator = LogicalOperator.And
};
var secondFilter = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "exdyn_agreementstatus",
Operator = ConditionOperator.Equal,
Values = { 2 } // active {2}
}
}
};
var entity = _organizationService.GetEntityCollectionWithJoin
("exdyn_employeecontract", "exdyn_companyagreement",
"exdyn_companyagreementid", "exdyn_companyagreementid", JoinOperator.Inner,
cols, secondEntityCols, filter, secondFilter).Entities.FirstOrDefault();
==============
Code Use to connect :
public class WebModule : Module
{
protected override void Load(ContainerBuilder builder)
{
// Register your Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
// Register your MVC controllers.
builder.RegisterControllers(Assembly.GetExecutingAssembly());
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
builder.RegisterFilterProvider();
builder.Register(c => new WebConfigurationSettings()).As<IWebSettings>().SingleInstance();
builder.Register(GetOrganizationServiceManagement).SingleInstance();
builder.Register(GetOrganizationProxy).InstancePerRequest();
builder.Register(c => new ExceptionHandler()).SingleInstance();
builder.Register(c => new EmployeeService(c.Resolve<IOrganizationService>()))
.As<IEmployeeService>()
.EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new AttendanceService(c.Resolve<IOrganizationService>()))
.As<IAttendanceService>().EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new ContractService(c.Resolve<IOrganizationService>()))
.As<IContractService>().EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new InquiryService(c.Resolve<IOrganizationService>(), c.Resolve<ILookupService>()))
.As<IInquiryService>().EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new LookupService(c.Resolve<IOrganizationService>()))
.As<ILookupService>().EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new LeaveRequestService(c.Resolve<IOrganizationService>(),
c.Resolve<IContractService>(), c.Resolve<ILookupService>()))
.As<ILeaveRequestService>().EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new PurchaseRequestService(c.Resolve<IOrganizationService>(), c.Resolve<ILookupService>()))
.As<IPurchaseRequestService>().EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new NotificationService(c.Resolve<IOrganizationService>()))
.As<INotificationService>().EnableInterfaceInterceptors()
.InterceptedBy(typeof(ExceptionHandler))
.InstancePerRequest();
builder.Register(c => new CacheClient())
.As<ICacheClient>()
.SingleInstance();
}
private static IServiceManagement<IOrganizationService> GetOrganizationServiceManagement(IComponentContext ctx)
{
var settings = ctx.Resolve<IWebSettings>();
return ServiceConfigurationFactory.CreateManagement<IOrganizationService>(
new Uri(settings.OrganizationUrl));
}
private static IOrganizationService GetOrganizationProxy(IComponentContext ctx)
{
var svcMgmt = ctx.Resolve<IServiceManagement<IOrganizationService>>();
var settings = ctx.Resolve<IWebSettings>();
var credentials = new AuthenticationCredentials();
credentials.ClientCredentials.UserName.UserName = settings.SystemUserName;
credentials.ClientCredentials.UserName.Password = settings.SystemUserPassword;
var authCredentials = svcMgmt.Authenticate(credentials);
//return new OrganizationServiceProxy(svcMgmt, authCredentials.SecurityTokenResponse);
return new OrganizationServiceProxy(svcMgmt, authCredentials.ClientCredentials);
}
}