我一直在发布有关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是否存在问题。在这方面的任何帮助将不胜感激。
答案 0 :(得分:0)
您需要在连接字符串中包括AuthType = Office365。
用下面的两行替换代码的第2行。
{domain}是您的AD域
string conStr = $“ AuthType = IFD; HomeRealmUri = {hru}; Domain = {domain}; Url = {url}; Username = {username}; Password = {pass}”; CrmServiceClient服务=新的CrmServiceClient(conStr);
答案 1 :(得分:0)
我很少需要设置安全协议,因此您可以尝试跳过设置安全协议,并在CrmServiceClient
构造函数中使用简单的连接字符串。
首先,根据您的版本设置连接字符串:
CRM 2016之前的本地IFD:
var connectionString = "Url=https://contoso.litware.com; Username=someone@litware.com; Password=password; AuthType=IFD;"
CRM 2016及更高版本(v8.0 +)的本地IFD
var connectionString = "ServiceUri=https://contoso.litware.com/contoso; Domain=contoso; Username=contoso\administrator; Password=password; AuthType=IFD; LoginPrompt=Never;"
然后将其传递给构造函数:
var svc = new CrmServiceClient(connectionString);
然后您可以检查服务是否准备就绪:
if(!svc.IsReady) { throw new Exception("Service not ready");}