简体   繁体   English

访问Dynamics365时发生错误“ Microsoft.Xrm.Sdk.dll中发生System.ServiceModel.Security.MessageSecurityException”

[英]An error “System.ServiceModel.Security.MessageSecurityException' occurred in Microsoft.Xrm.Sdk.dll” occurs when accessing Dynamics365

I am trying to get data from MS Dynamics but an error "'System.ServiceModel.Security.MessageSecurityException' occurred in Microsoft.Xrm.Sdk.dll but was not handled in user code 我正在尝试从MS Dynamics获取数据,但是Microsoft.Xrm.Sdk.dll中出现错误“'System.ServiceModel.Security.MessageSecurityException”,但未在用户代码中处理

Additional information: An unsecured or incorrectly secured fault was received from the other party. 附加信息:从另一方收到不安全或不正确安全的故障。 See the inner FaultException for the fault code and detail." arises the code is as follows 有关错误代码和详细信息,请参见内部FaultException。”出现的代码如下。

protected void Page_Load(object sender, EventArgs e)
    {
        IOrganizationService service = GetCRMService();
        QueryExpression query = new QueryExpression("account");
        query.ColumnSet.AllColumns = true;
        query.Criteria.AddCondition("name", ConditionOperator.NotEqual, "ksllls");
        EntityCollection collection = service.RetrieveMultiple(query);

        DataTable dt = new DataTable();
        dt.Columns.Add("name");
        dt.Columns.Add("accountnumber");
        foreach (Entity entity in collection.Entities)
        {
            DataRow dr = dt.NewRow();
            dr["name"] = entity.Attributes["name"].ToString();
            if (entity.Contains("accountnumber"))
            {
                dr["accountnumber"] = entity.Attributes["accountnumber"].ToString();
            }
            dt.Rows.Add(dr);
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }


    public IOrganizationService GetCRMService()
    {

        string UserName = "mydomain.com";
        string Password = "*****";
        ClientCredentials Credentials = new ClientCredentials();
        IOrganizationService Service;
        Credentials.UserName.UserName = UserName;
        Credentials.UserName.Password = Password;

        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
        //This URI need to be updated to match the servername and organisation for the environment

        string CRMServer = ConfigurationManager.AppSettings["crmserverurl"].ToString();
        Uri OrganizationUri = new Uri(CRMServer);
        Uri HomeRealmUri = null;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        // OrgaizationServiceProxy  ServiceProxy

        using (OrganizationServiceProxy ServiceProxy = new OrganizationServiceProxy(OrganizationUri, null, Credentials, null))
        {
            Service = (IOrganizationService)ServiceProxy;
        }
        return Service;
    }

The error is in the line EntityCollection collection = service.RetrieveMultiple(query); 错误在EntityCollection collection = service.RetrieveMultiple(query);行中。 Can anyone help me solve it 谁能帮我解决

I faced the similar issue and tried to remove and add again the microsoft.xrm.sdk.dll. 我遇到了类似的问题,并尝试删除并再次添加microsoft.xrm.sdk.dll。 The login credentials for your CRM that you mentioned in your code may be different or incorrect. 您在代码中提到的CRM的登录凭据可能不同或不正确。 I am saying so because i faced the same issue and found that my login credentials were incorrect so i corrected the credentials and it worked fine. 我之所以这样说是因为我遇到了同样的问题,并且发现我的登录凭据不正确,所以我更正了凭据并且它工作正常。

Thanks, Shubham Grover 谢谢,Shubham Grover

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有这个错误 System.ServiceModel.Security.MessageSecurityException - I have this error System.ServiceModel.Security.MessageSecurityException WCF中的'System.ServiceModel.Security.MessageSecurityException' - 'System.ServiceModel.Security.MessageSecurityException' in WCF Dynamics 365:为什么 .net6 控制台客户端出现“Xrm.Sdk WSDL”错误? - Dynamics 365: why I get "Xrm.Sdk WSDL" error for .net6 console client? 发生错误。 请与系统管理员联系,或参阅Microsoft Dynamics CRM SDK故障排除指南 - An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide Dynamics365:创建报价后停止复制产品 - Dynamics365 : Stop Products from Copying when Quote is Created 为什么在Dynamics 365 XRM工具SDK中使用IOrganizationService而不是CrmServiceClient? - Why use IOrganizationService instead of CrmServiceClient in Dynamics 365 XRM tooling SDK? Microsoft Dynamics 365 SDK Core 程序集 .NET Core 移植错误 - Microsoft Dynamics 365 SDK Core Assemblies .NET Core Porting Error 在本地调试 Dynamics365 代码活动 - Debugging a Dynamics365 code activity locally “ mscorlib.dll中发生了'System.ServiceModel.ProtocolException类型的异常,但未在用户代码中处理”错误 - “An exception of type 'System.ServiceModel.ProtocolException' occurred in mscorlib.dll but was not handled in user code” error 如何使用 Dynamics 365 XRM Tooling SDK 通过主 ID 一般获取实体记录的枚举集 - How to generically get enumerated set of entity records by primary id with Dynamics 365 XRM Tooling SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM