Answered by:
Register webservice in IIS

Question
-
Hi,
I created a web service (asmx page) to create records in CRM.
If i test this page in Visual Studio (on my local pc), it works fine (and records are created in CRM).
But, i need to deploy it in IIS so that the service can be called.I did this, but when executing the webservice it gives me an error.
"The data protection operation was unsuccessful. This may have
been caused by not having the user profile loaded for the current thread's user
context, which may be the case when the thread is impersonating."If i debug, my code stops before the part to get the Device Credentials:
deviceCredentials = this.GetDeviceCredentials();
protected virtual ClientCredentials GetDeviceCredentials()
{
return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
}It's like I am not connected in the web service to CRM.
My credentials are provided in clientcredentials (hard coded).What could be the problem?
thanks
Tuesday, June 30, 2015 6:46 AM
Answers
-
use the simplified connection:
CrmConnection crmConnection = CrmConnection.Parse("Url=https://XXX.crm.dynamics.com; Username=user@domain.onmicrosoft.com; Password=passwordhere;"); IOrganizationService service = new OrganizationService(crmConnection);
this sample if for CRM online, for OnPremise it will be like:
CrmConnection crmConnection = CrmConnection.Parse("Url=https://XXX.crm.dynamics.com; Domain=mydomain; Username=usernamehere; Password=passwordhere;"); IOrganizationService service = new OrganizationService(crmConnection);
(note the Domain part)
you get that error because your code is using an old library with the option for Windows Live ID authentication that required devicename and devicepassword inside the connection string.
My blog: www.crmanswers.net - CRM Theme Generator
- Proposed as answer by Guido PreiteMVP Tuesday, June 30, 2015 7:34 AM
- Marked as answer by Alexander_DM Tuesday, June 30, 2015 2:08 PM
Tuesday, June 30, 2015 7:34 AM
All replies
-
use the simplified connection:
CrmConnection crmConnection = CrmConnection.Parse("Url=https://XXX.crm.dynamics.com; Username=user@domain.onmicrosoft.com; Password=passwordhere;"); IOrganizationService service = new OrganizationService(crmConnection);
this sample if for CRM online, for OnPremise it will be like:
CrmConnection crmConnection = CrmConnection.Parse("Url=https://XXX.crm.dynamics.com; Domain=mydomain; Username=usernamehere; Password=passwordhere;"); IOrganizationService service = new OrganizationService(crmConnection);
(note the Domain part)
you get that error because your code is using an old library with the option for Windows Live ID authentication that required devicename and devicepassword inside the connection string.
My blog: www.crmanswers.net - CRM Theme Generator
- Proposed as answer by Guido PreiteMVP Tuesday, June 30, 2015 7:34 AM
- Marked as answer by Alexander_DM Tuesday, June 30, 2015 2:08 PM
Tuesday, June 30, 2015 7:34 AM -
The LoadOrRegisterDevice method reads credentials from a file in the user's profile. There are 2 things you have to do to make this work when running in IIS:
- Ensure the credentials are registered for the user that is the identity of the IIS application pool in which your application runs
- Ensure the application pool loads the user profile. In IIS Manager, go to Advanced Properties of the application pool and ensure Load User Profile = true
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
Tuesday, June 30, 2015 1:59 PMModerator -
Thanks for the answers.
I used the code that Guido described and it works.Thanks
Tuesday, June 30, 2015 2:09 PM