最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Connecting to Dynamics CRM fails with proper credentials and message The HTTP request was forbidden with client authenticat

programmeradmin1浏览0评论

I am using the XrmToolkit and a connection string to connect to Dynamics 365, with the following call:

var crmServiceClient = new CrmServiceClient(connectionString);

The same code with the same connection string (same credentials, same server, same AppId, etc) works from some machines. However, from other machines, it fails with the following error (some data obfuscated with asterisks):

The HTTP request was forbidden with client authentication scheme 'Anonymous'.

How am I to understand this? I have turned on detailed tracing, and here is the complete trace log for the failed connection attempt:

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : Initialize CRM connection Started - AuthType: OAuth
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : Direct Login Process Started
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Attempting to Connect to Uri https://**********.crm.dynamics/XRMServices/2011/Organization.svc
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Start: 256 : BuildOrgConnectUri CoreClass ()
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : DiscoveryServer indicated anization service location = https://********.crm.dynamics/XRMServices/2011/Organization.svc
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Stop: 512 : BuildOrgConnectUri CoreClass ()
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Organization Service URI is = https://**********.crm.dynamics/XRMServices/2011/Organization.svc
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : ConnectAndInitCrmOrgService - Initializing Organization Service Object
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : ConnectAndInitCrmOrgService - Requesting connection to Organization with CRM Version: No anization data available
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : AuthenticateService - found authority with name /********-****-****-****-************/oauth2/authorize
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : AuthenticateService - found resource with name https://********.crm.dynamics/
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : ObtainAccessToken - CRED
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : Added WebClient Header Hooks to the Request object.
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : ConnectAndInitCrmOrgService - Proxy created, total elapsed time: 00:00:02.5677367
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Querying Organization Instance Details. Request ID: ********-****-****-****-************
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Invalid Login Information : The HTTP request was forbidden with client authentication scheme 'Anonymous'.
Source  : mscorlib
Method  : HandleReturnMessage
Date    : 3/12/2025
Time    : 9:29:29 AM
Error   : The HTTP request was forbidden with client authentication scheme 'Anonymous'.
Stack Trace     : Server stack trace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.WebServiceClient.OrganizationWebProxyClient.<>c__DisplayClass40_0.<ExecuteCore>b__0()
   at Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient`1.ExecuteAction[TResult](Func`1 action)
   at Microsoft.Xrm.Sdk.WebServiceClient.OrganizationWebProxyClient.ExecuteCore(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.WebServiceClient.OrganizationWebProxyClient.Execute(OrganizationRequest request)
   at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.RefreshInstanceDetails(IOrganizationService crmService, Uri uriOfInstance)
   at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.DoDirectLogin(Boolean IsOnPrem)
   at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.InitCRM2011Service()
======================================================================================================================
Inner Exception Level 1 :
Source  : System
Method  : GetResponse
Date    : 3/12/2025
Time    : 9:29:29 AM
Error   : The remote server returned an error: (403) Forbidden.
Stack Trace     : at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
======================================================================================================================

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM
Source  : Not Provided
Method  : Not Provided
Date    : 3/12/2025
Time    : 9:29:29 AM
Error   : Unable to Login to Dynamics CRM
Stack Trace     : Not Provided
======================================================================================================================
发布评论

评论列表(0)

  1. 暂无评论