private static void ExecuteWhoAmI(ClientCredentials credentials, string serviceUrl) { using (OrganizationServiceClient client = new OrganizationServiceClient("CustomBinding_IOrganizationService", new EndpointAddress(serviceUrl))) { ApplyCredentials(client, credentials); OrganizationRequest request = new OrganizationRequest(); request.RequestName = "WhoAmI"; OrganizationResponse response = (OrganizationResponse)client.Execute(request); foreach (KeyValuePair <string, object> result in response.Results) { if ("UserId" == result.Key) { Console.WriteLine("User ID: {0}", result.Value); break; } } } }
private static void ExecuteWhoAmI(SecurityToken token, string serviceUrl, Uri issuerUri) { using (OrganizationServiceClient client = new OrganizationServiceClient("CustomBinding_IOrganizationService", new EndpointAddress(serviceUrl))) { client.ConfigureCrmOnlineBinding(issuerUri); client.Token = token; OrganizationRequest request = new OrganizationRequest(); request.RequestName = "WhoAmI"; OrganizationResponse response = (OrganizationResponse)client.Execute(request); foreach (KeyValuePair <string, object> result in response.Results) { if ("UserId" == result.Key) { Console.WriteLine("User ID: {0}", result.Value); break; } } } }
private static void ExecuteWhoAmI(SecurityToken token, string serviceUrl, Uri issuerUri) { using (OrganizationServiceClient client = new OrganizationServiceClient("CustomBinding_IOrganizationService", new EndpointAddress(serviceUrl))) { client.ConfigureCrmOnlineBinding(issuerUri); client.Token = token; OrganizationRequest request = new OrganizationRequest(); request.RequestName = "WhoAmI"; OrganizationResponse response = (OrganizationResponse)client.Execute(request); foreach (KeyValuePair<string, object> result in response.Results) { if ("UserId" == result.Key) { Console.WriteLine("User ID: {0}", result.Value); break; } } } }