class Program
{
static void Main(string[] args)
{
String userName;
String password;
userName = <your-live-ID>;
password = <live-ID-password>;
organizationUrl = "https://<your-organization-name>.crm.dynamics.com/XRMServices/2011/Organization.svc";
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = userName;
credentials.UserName.Password = password;
IServiceManagement<IOrganizationService>
orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new
Uri(organizationUrl));
AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials = credentials;
authCredentials.SupportingCredentials = new
AuthenticationCredentials();
authCredentials.SupportingCredentials.ClientCredentials =
Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
AuthenticationCredentials tokenCredentials =
orgServiceManagement.Authenticate(authCredentials);
var
organizationTokenResponse = tokenCredentials.SecurityTokenResponse;
OrganizationServiceProxy _serviceProxy;
IOrganizationService _service;
using (_serviceProxy = new
OrganizationServiceProxy(orgServiceManagement,
organizationTokenResponse))
{
_service = (IOrganizationService)_serviceProxy;
WhoAmIResponse response = (WhoAmIResponse)_service.Execute(new WhoAmIRequest());
Console.WriteLine(response.UserId.ToString());
}
Console.ReadLine();
}
}
Hi anton,
ReplyDeleteNice post,thanks for sharing this information .Looking forward for more useful posts like this.
Dynamics CRM Developers
this code is working when we Run this Code from Visual Studio.but once I deploy this code this is not working and getting this error
ReplyDeleteMost likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.
Really great article on Microsoft CRM. Loved it man. Keep up the good work.
ReplyDelete