|
|
|
SUMMARY
This article describes the recommended way to authenticate specific user
credentials by using the Microsoft Customer Relationship Management (CRM)
Security Model from an external process.
As a result, the following Microsoft C# code loads the CredentialCache method
of the Microsoft CRM proxy class on the server where the process that is
integrating with Microsoft CRM resides.
|
{
// Set the name of the server to the name of the Microsoft CRM API Web server.
string server = "CRMWebServer";
// Virtual Directory on the Microsoft CRM API Web server.
string virtualDirectory = "mscrmservices";
string strDir = "http:/" + server + "" + virtualDirectory + "";
// Instantiate a Microsoft CRM BizUser object (Member of
Microsoft.CRM.Proxy.dll).
Microsoft.CRM.Proxy.BizUser bizUser = new Microsoft.CRM.Proxy.BizUser ();
bizUser.Url = strDir + "BizUser.srf";
// Instantiate a System.Net.CredentialCache object.
System.Net.CredentialCache credentialCache = new CredentialCache();
// Instantiate a System.Net.NetworkCredential object passing in the Active
Directory UserName,
// Password and Domain that will be used to authenticate into the Microsoft CRM
Security Model.
// Set up this user in Microsoft CRM and give the user the appropriate License
Keys and Roles.
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential +
("User1","Password","Domain");
// Add a value to the CredentialCache to indicate the URI of the Microsoft CRM
Server, "NTLM",
// which represents integrated Windows authenticated and the credentials of
// the user who is to be used for authentication.
credentialCache.Add(new Uri("http:/" + server), "NTLM",
credentials);
bizUser.Credentials = credentialCache;
}
|
Each time that the Web application has to authenticate to the Microsoft CRM API
classes and pass lead data, the application passes the credentials of User 1.
When a record is created or updated from the Web application to Microsoft CRM,
the CreatedBy field and the LastUpdatedBy field are populated with User 1's
credentials.
|