如何解决Microsoft.Xrm.Tooling.Connector.CrmServiceClient 安全令牌每 5 小时过期一次,出现用户身份验证失败错误
我是 WCF 的新手,我创建了 WCF 服务,该服务连接并从动态 CRM 中提取数据。一切正常,但 5 小时后我收到以下错误,由于此错误,我看到异常 The user authentication Failed!
。我知道安全令牌已过期,因此我收到身份验证错误,重新启动应用程序池后一切似乎都很好。
什么会导致安全令牌过期?或者如何重新发行令牌?
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Warning: 4 : Claims Connection reset tripped SecurityToken is Not Null Start From is Valid True End At is Valid False Microsoft.Xrm.Tooling.Connector.CrmServiceClient Warning: 4 : Re-Authenticating due to expired token @ 05/20/2021 04:12:23
我在连接字符串中使用 AuthType=IFD
,下面是我的编码,我从 web.config 文件传递连接字符串。我在配置文件中使用 RequireNewInstance=True;
,因为我有两个 crm 服务器要连接。
<add name="crmconnectionstring" connectionString="Url=https://urlhere; AuthType=IFD; RequireNewInstance=True;Domain=testdomain; Username=testusername; Password=; " />
public OrganizationServiceProxy service_;
CrmServiceClient CrmServiceClient_= new
CrmServiceClient(ConfigurationManager.ConnectionStrings["crmconnectionstring"].ConnectionString);
if (!CrmServiceClient_.IsReady)
{
if (CrmServiceClient_.LastCrmException != null)
throw CrmServiceClient_.LastCrmException;
throw new InvalidOperationException(CrmServiceClient_.LastCrmError);
}
service_ = CrmServiceClient_.OrganizationServiceProxy;
更新 1:
我已尝试更新令牌,但仍然无效。我正在拼命寻求支持。
public OrganizationServiceProxy service;
service = CrmServiceClient_.OrganizationServiceProxy; if (null != this.service.SecurityTokenResponse && DateTime.UtcNow.AddMinutes(15) >= this.service.SecurityTokenResponse.Response.Lifetime.Expires) { 尝试 { this.service.Authenticate(); } 捕获(通信异常) { if (null == this.service.SecurityTokenResponse || DateTime.UtcNow >= this.service.SecurityTokenResponse.Response.Lifetime.Expires) { 扔; } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。