CrmServiceClient svc = new CrmServiceClient("connectionstring");
// ServiceClient svc = new ServiceClient("connectionstring");
// Verify that you are connected
if (svc != null && svc.IsReady)
{
// Create an account record
Dictionary<string, CrmDataTypeWrapper> inData = new Dictionary<string, CrmDataTypeWrapper>();
inData.Add("name", new CrmDataTypeWrapper("Sample Account Name", CrmFieldType.String));
inData.Add("address1_city", new CrmDataTypeWrapper("Redmond", CrmFieldType.String));
inData.Add("telephone1", new CrmDataTypeWrapper("555-0160", CrmFieldType.String));
accountId = ctrl.CrmConnectionMgr.svc.CreateNewRecord("account", inData);
// Verify if the account is created.
if (accountId != Guid.Empty)
{
Console.WriteLine(“Account created.”);
}
}
else
{
// Display the last error.
Console.WriteLine("An error occurred: {0}", svc.LastCrmError);
// Display the last exception message if any.
Console.WriteLine(svc.LastCrmException.Message);
Console.WriteLine(svc.LastCrmException.Source);
Console.WriteLine(svc.LastCrmException.StackTrace);
return;
}
アプリケーション コードでの接続文字列の使用については、次の重要な情報をお読みください。
重要
Microsoft では、利用可能な最も安全な認証フローを使用することをお勧めします。 この記事で説明する認証フローは、アプリケーションに対する非常に高い信頼を必要とし、他のフローには存在しないリスクを伴います。 このフローは、マネージド ID など、他のより安全なフローが実行できない場合にのみ使用してください。
CrmServiceClient svc = new CrmServiceClient(connectionstring);
// ServiceClient svc = new ServiceClient("connectionstring");
// Verify that you are connected.
if (svc != null && svc.IsReady)
{
// Create and attach a note.
inData.Clear();
inData.Add("subject", new CrmDataTypeWrapper("This is a NOTE from the API" , CrmFieldType.String));
inData.Add("notetext", new CrmDataTypeWrapper("This is text that will go in the body of the note" , CrmFieldType.String));
Guid noteID = svc.CreateAnnotation("account", accountId, inData);
}
else
{
// Display the last error.
Console.WriteLine("An error occurred: {0}", svc.LastCrmError);
// Display the last exception message if any.
Console.WriteLine(svc.LastCrmException.Message);
Console.WriteLine(svc.LastCrmException.Source);
Console.WriteLine(svc.LastCrmException.StackTrace);
return;
}