Sunday, September 23, 2012

the caller was not authenticated by the service MS crm 2011 C#

while writing a batch job by using the MS CRM 2011 SDK, i got the below exception
"the caller was not authenticated by the service".

but the same was working in my VPC, but while deployed in my Dev Server, i got the exception.
what i was missing the the domain name while getting the credential.
after added the domain name , it has resolved... (but make sure about the two servers time, if the batch job and CRM servers are different).
initially i was using the below code...

ClientCredentials creds = new ClientCredentials();
                // Credentials
                creds.UserName.UserName = userName;
                creds.UserName.Password = password;
                OrganizationServiceProxy service = new OrganizationServiceProxy(new Uri(orgURL), null, creds, null);
                service.Timeout = new TimeSpan(0, 5, 0);
                //service.EnableProxyTypes();
                return (IOrganizationService)service;

then changed to the below and it works fine... :)

ClientCredentials creds = new ClientCredentials();
                // Credentials
                creds.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
                OrganizationServiceProxy service = new OrganizationServiceProxy(new Uri(orgURL), null, creds, null);
                service.Timeout = new TimeSpan(0, 5, 0);
                //service.EnableProxyTypes();
                return (IOrganizationService)service;

Regards,
yes.sudhanshu

1 comment: