AuthType = AD
-
创建项目模板是.NET framework 4.6.2的控制台程序
-
添加nuget包
Microsoft.CrmSdk.CoreAssemblies
,Microsoft.CrmSdk.XrmTooling.CoreAssembly
-
Program类添加以下代码
using System; using System.Configuration; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Tooling.Connector; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { CrmServiceClient service = new CrmServiceClient(ConfigurationManager.ConnectionStrings["Connect"].ConnectionString); // Obtain information about the logged on user from the web service. Guid userid = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId; var systemUser = service.Retrieve("systemuser", userid, new ColumnSet(new string[] { "firstname", "lastname" })); Console.WriteLine("Logged on user is {0} {1}.", systemUser.GetAttributeValue<string>("firstname"), systemUser.GetAttributeValue<string>("lastname")); // Retrieve the version of Microsoft Dynamics CRM. RetrieveVersionRequest versionRequest = new RetrieveVersionRequest(); RetrieveVersionResponse versionResponse = (RetrieveVersionResponse)service.Execute(versionRequest); Console.WriteLine("Microsoft Dynamics CRM version {0}.", versionResponse.Version); Console.ReadKey(); } } }
-
App.config 添加配置
-
请根据你的测试环境修改连接字符串中的Domain,Username,Password以及Url
<?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> <add name="Connect" connectionString=" AuthType=AD; Domain=yourDomain; Username=yourUsername; Url=https://contosotest.crm.dynamics.com; Password=yourPassword;"/> </connectionStrings> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> </startup> </configuration>
-
-
运行项目