In my case ServiceConfigurationFactory class helped me. Below is peace of code how I'm retrieving IOrganizationService instance:
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = "username";
credentials.UserName.Password = "password";
IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD);
using (Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
IOrganizationService _service = (IOrganizationService)_serviceProxy;
WhoAmIResponse response = (WhoAmIResponse)_service.Execute(new WhoAmIRequest());
Console.WriteLine(response.UserId.ToString());
Console.ReadLine();
}
Thanks Anton
ReplyDeleteExcellent
ReplyDeleteAmazing Code.
ReplyDeleteCan we get the service with defalut credentials like
ReplyDeletecredentials.Windows.ClientCredential =System.Net.CredentialCache.DefaultNetworkCredentials;
Am trying to connect to crm with network credentials but it saying as "user authentication failed"
Can you please help me...
In some cases it works in other cases it doesn't. Actually it depends on your network configuration and on what kind of application (desktop, web etc.) is your client and how do you run it.
DeleteI have the same problem with a console application.
DeleteI can't fix the username/password, the app must run in the name of the current user.
Have any ideas or advise?
Thanks
System.Net.CredentialCache.DefaultNetworkCredentials is assigned to "credentials.Windows.ClientCredential" where as in IFD or Claim based implementation "credentials.Username.username / password" is used to authenticate.
Deleteit works, thanks!!!
ReplyDeleteHi Anton, I get a strange exception "The authentication endpoint Username was not found on the configured Secure Token Service!". Can you kindly help me to figure this out
ReplyDeleteThank you so much!! I struggled with this for a whole day, and found no other resources to explain Ifd. Linked here from SO question.
ReplyDelete