0

CRM Dynamics 365 にアクセスする必要があります。以下のコードを使用して、「ADFS (IFD) 認証」で問題なくアクセスできますが、CRM Online では「Dynamics 365 https://OrgName.api.crm4.dynamics.com/XRMServices/2011/ 」 Organization.svc "

このエラーを取得:

保護されていない、または誤って保護された障害が相手から受信されました。障害コードと詳細については、内部の FaultException を参照してください。

Server stack trace: 
   at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   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 System.ServiceModel.Security.IWSTrustContract.Issue(Message message)
   at System.ServiceModel.Security.WSTrustChannel.Issue(RequestSecurityToken rst, RequestSecurityTokenResponse& rstr)
   at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.Issue(AuthenticationCredentials authenticationCredentials)
   at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateInternal(AuthenticationCredentials authenticationCredentials)
   at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateWithOrgIdForACS(AuthenticationCredentials authenticationCredentials, Uri identifier)
   at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateOnlineFederationInternal(AuthenticationCredentials authenticationCredentials)
   at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.Authenticate(AuthenticationCredentials authenticationCredentials)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration.Authenticate(AuthenticationCredentials authenticationCredentials)

この私のコード:

public static IOrganizationService GetService()
{

    try
    {
        OrganizationServiceProxy _serviceProxy;

        string userName = "";
        string password = "";
        string domain = "";
        Uri serviceUri;


        serviceUri = new Uri(ConfigurationManager.AppSettings["URL"]);
        userName = ConfigurationManager.AppSettings["UserName"];
        password = ConfigurationManager.AppSettings["Password"];
        domain = ConfigurationManager.AppSettings["domain"];


        IServiceManagement<IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(serviceUri);

        if (orgServiceManagement.AuthenticationType == AuthenticationProviderType.Federation)
        {
            // ADFS (IFD) Authentication
            ClientCredentials clientCred = new ClientCredentials();
            clientCred.UserName.UserName = userName;
            clientCred.UserName.Password = password;
            _serviceProxy = new OrganizationServiceProxy(orgServiceManagement, clientCred);
        }
        else if (orgServiceManagement.AuthenticationType == AuthenticationProviderType.OnlineFederation)
        {
            // Online authentication
            AuthenticationCredentials authCredentials = new AuthenticationCredentials();

            authCredentials.ClientCredentials.UserName.UserName = userName;
            authCredentials.ClientCredentials.UserName.Password = password;

            // Error getting here
            AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials); 


            _serviceProxy = new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);
        }
        else
        {
            // On-Premise, non-IFD authentication
            ClientCredentials credentials = new ClientCredentials();
            credentials.Windows.ClientCredential = new NetworkCredential(userName, password, domain);
            _serviceProxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
        }

        _serviceProxy.EnableProxyTypes();


    }
    catch (Exception e)
    {

    }

    return (IOrganizationService)_serviceProxy;
}
4

3 に答える 3

0

この記事の修正を試してください。

これを修正するには、プロファイル フォルダー C:\Users\ にある LiveDeviceID という名前のデバイス登録フォルダーを削除してみてください。その後、再度接続を試みます。

于 2016-12-21T09:58:52.027 に答える