c# - 将连接传递到 Dynamics 365 CRM 后获取服务
问题描述
我一直在发布有关 Dynamics 365 集成的问题,我将简要解释我面临的问题。我用来连接的代码是这个
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
CrmServiceClient conn = new CrmServiceClient(new NetworkCredential("<username>", "<Password>", "<domain>"), Microsoft.Xrm.Tooling.Connector.AuthenticationType.IFD, "<url>", "<port>", "<OrgName>");
_orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
// Retrieve the version of Microsoft Dynamics CRM.
RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
RetrieveVersionResponse versionResponse = (RetrieveVersionResponse)_orgService.Execute(versionRequest);
Console.WriteLine("Microsoft Dynamics CRM version {0}.", versionResponse.Version);
凭据不会返回服务请求,这是我收到的错误日志。
Inner Exception Level 3 :
Source : System
Method : Receive
Date : 26/09/2018
Time : 11:19:51 AM
Error : An existing connection was forcibly closed by the remote host
Stack Trace : at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32
offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationWebProxyClient is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
The application terminated with an error.
Microsoft 提供的使用工具连接器的示例程序都不起作用。我不能使用 OrganizationClient 连接,因为集成不会使用 Microsoft.SDK.Client.dll 运行。我被困在这里,我想知道这是否是托管 CRM 的问题。对此的任何帮助将不胜感激。
解决方案
您需要在连接字符串中包含 AuthType=Office365。
用下面的这两行替换代码的第 2 行。在哪里
- {url} 是您的 D365 实例 URL
- {username} 是您的 D365 用户名(尝试:用户名或域\用户名)
- {password} 是您的 D365 密码
- {hru} 是您的 ADFS 主域 url
{domain} 是您的 AD 域
string conStr = $"AuthType=IFD;HomeRealmUri={hru};Domain={domain};Url={url};Username={username};Password={pass}"; CrmServiceClient 服务 = 新 CrmServiceClient(conStr);
推荐阅读
- amazon-redshift - 与 Amazon Redshift 中的基表相比,使用物化视图有什么优势?
- ionic-framework - Ionic SumUp 终端付款回调不起作用
- python - Python Scrape H2 和 Selenium 价格
- javascript - 创建原型时如何使用远箭头语法?
- for-loop - BATCH:在 For 循环中使用 IF Exist 到远程机器的语法(For /L)
- xcode - UITableView 需要 cell=nil 才能正确返回单元格
- perl - 当一个输入字符串是另一个输入字符串的子字符串时替换字符串
- amazon-web-services - 如何使用密钥和秘密访问 s3 存储桶?
- c# - 使用实体框架在 ASP.NET 中创建登录失败
- javascript - Discord.js 机器人仅用于一个角色?