Repository navigation
Expand file tree
/
Copy pathXrmServiceManagerSamples.cs
More file actions
149 lines (130 loc) · 7.43 KB
/
Copy pathXrmServiceManagerSamples.cs
File metadata and controls
149 lines (130 loc) · 7.43 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*================================================================================================================================
This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object
code form of the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market Your software
product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the
Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims
or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code.
=================================================================================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
namespace Microsoft.Pfe.Xrm.Samples
{
public class XrmServiceManagerSamples
{
/// <summary>
/// Demonstrates a basic Active Directory connection to Organization.svc using a username, password, and domain
/// </summary>
/// <remarks>
/// OrganizationServiceManager stores endpoint metadata. Instance can be reused to construct multiple organization service channels (OrganizationServiceProxy)
/// </remarks>
public static void BasicADConnectionToCrm()
{
var serverUri = XrmServiceUriFactory.CreateOrganizationServiceUri("http://mycrmserver:5555/myorganization");
var manager = new OrganizationServiceManager(serverUri, "username", "password", "mydomain");
using (var proxy = manager.GetProxy())
{
//Do organization requests...
}
}
/// <summary>
/// Demonstrates a basic claims-based connection to Organization.svc using a username and password
/// </summary>
/// <remarks>
/// OrganizationServiceManager stores endpoint metadata and security token. Instance can be reused to construct multiple organization service channels (OrganizationServiceProxy)
/// </remarks>
public static void BasicClaimsConnectionToCrm()
{
var serverUri = XrmServiceUriFactory.CreateOrganizationServiceUri("https://mycrmserver:5555/myorganization");
var manager = new OrganizationServiceManager(serverUri, "username", "password");
using (var proxy = manager.GetProxy())
{
//Do organization requests...
}
}
/// <summary>
/// Demonstrates an online-federated connection to Organization.svc using a userprincipalname and password
/// </summary>
/// <remarks>
/// OrganizationServiceManager stores endpoint metadata and security token. Instance can be reused to construct multiple organization service channels (OrganizationServiceProxy)
/// </remarks>
public static void BasicConnectionToCrmOnline()
{
var serverUri = XrmServiceUriFactory.CreateOnlineOrganizationServiceUri("myorganization", CrmOnlineRegion.NA);
var manager = new OrganizationServiceManager(serverUri, "username@mydomain.onmicrosoft.com", "password");
using (var proxy = manager.GetProxy())
{
//Do organization requests...
}
}
/// <summary>
/// Demonstrates a claims-based, cross-realm connection to Organization.svc using a username, password, and alternate realm
/// </summary>
/// <remarks>
/// Authentication will be handled by federated realm's identity provider. Issued token will be converted to current realm token that CRM will accept.
/// OrganizationServiceManager stores endpoint metadata and security token. Instance can be reused to construct multiple organization service channels (OrganizationServiceProxy)
/// </remarks>
public static void BasicCrossRealmConnectionToCrm()
{
var serverUri = XrmServiceUriFactory.CreateOrganizationServiceUri("https://mycrmserver:5555/myorganization");
var manager = new OrganizationServiceManager(serverUri, "username", "password", homeRealm: new Uri("https://myhomerealm.com"));
using (var proxy = manager.GetProxy())
{
//Do organization requests...
}
}
/// <summary>
/// Demonstrates a claims-based connection to Organization.svc using a pre-authenticated instance of AuthenticationCredentials
/// </summary>
/// <remarks>
/// OrganizationServiceManager stores endpoint metadata and security token. Instance can be reused to construct multiple organization service channels (OrganizationServiceProxy)
/// </remarks>
public static void BasicPreAuthConnectionToCrm(AuthenticationCredentials preAuthCredentials)
{
var serverUri = XrmServiceUriFactory.CreateOrganizationServiceUri("https://mycrmserver:5555/myorganization");
var manager = new OrganizationServiceManager(serverUri, preAuthCredentials);
using (var proxy = manager.GetProxy())
{
//Do organization requests...
}
}
/// <summary>
/// Demonstrates a basic connection to Discovery.svc using a username and password
/// </summary>
/// <remarks>
/// DiscoveryServiceManager stores endpoint metadata and security token (if necessary). Instance can be reused to
/// construct multiple discovery service channels (DiscoveryServiceProxy)
/// </remarks>
public static void BasicCrmDiscovery()
{
var serverUri = XrmServiceUriFactory.CreateDiscoveryServiceUri("https://mycrmserver:5555");
var discoManager = new DiscoveryServiceManager(serverUri, "username", "password");
using (var discoProxy = discoManager.GetProxy())
{
//Do discovery requests...
}
}
/// <summary>
/// Demonstrates a online-federated connection to Discovery.svc using a userprincipalname and password
/// </summary>
/// <remarks>
/// DiscoveryServiceManager stores endpoint metadata and security token (if necessary). Instance can be reused to
/// construct multiple discovery service channels (DiscoveryServiceProxy)
/// </remarks>
public static void BasicCrmOnlineDiscovery()
{
var discoManager = new DiscoveryServiceManager(XrmServiceUriFactory.DiscoveryServiceOnlineO365NAUri, "username@mydomain.onmicrosoft.com", "password");
using (var discoProxy = discoManager.GetProxy())
{
//Do discovery requests...
}
}
}
}