-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
85 lines (74 loc) · 2.89 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Pfe.Xrm;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
namespace OrganizationServiceProxyIssue
{
internal class Program
{
private static Uri serviceUri = new Uri("http://***/XRMServices/2011/Organization.svc");
private static void Main(string[] args)
{
ServicePointManager.DefaultConnectionLimit = 100;
//https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/best-practices-sdk#improve-service-channel-allocation-performance
PlainSdk();
Pfe();
Console.ReadLine();
}
private static void PlainSdk()
{
try
{
Console.WriteLine("Testing plain sdk");
var defaultCredentials = new AuthenticationCredentials()
{
ClientCredentials = new ClientCredentials()
{
Windows = { ClientCredential = CredentialCache.DefaultNetworkCredentials }
}
};
IServiceManagement<IOrganizationService> orgServiceManagement =
ServiceConfigurationFactory.CreateManagement<IOrganizationService>(serviceUri);
// go crazy on creating new proxies to simulate, for example, a high traffic web api.
Parallel.ForEach(Enumerable.Range(0, 100000), (index) =>
{
var proxy = new OrganizationServiceProxy(orgServiceManagement, defaultCredentials.ClientCredentials);
// From the link above:
// If you enable early-bound types on OrganizationServiceProxy through one of the EnableProxyTypes() methods,
// you must do the same on all service proxies that are created from the cached IServiceManagement < TService > object.
proxy.EnableProxyTypes();
proxy.Execute(new WhoAmIRequest());
});
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void Pfe()
{
try
{
Console.WriteLine("Testing plain pfe");
var manager = new OrganizationServiceManager(serviceUri);
Parallel.ForEach(Enumerable.Range(0, 100000), (index) =>
{
var proxy = manager.GetProxy();
proxy.EnableProxyTypes();
proxy.Execute(new WhoAmIRequest());
});
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}