繁体   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

我正在尝试从MS Dynamics获取数据,但是Microsoft.Xrm.Sdk.dll中出现错误“'System.ServiceModel.Security.MessageSecurityException”,但未在用户代码中处理

附加信息:从另一方收到不安全或不正确安全的故障。 有关错误代码和详细信息,请参见内部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;
    }

错误在EntityCollection collection = service.RetrieveMultiple(query);行中。 谁能帮我解决

我遇到了类似的问题,并尝试删除并再次添加microsoft.xrm.sdk.dll。 您在代码中提到的CRM的登录凭据可能不同或不正确。 我之所以这样说是因为我遇到了同样的问题,并且发现我的登录凭据不正确,所以我更正了凭据并且它工作正常。

谢谢,Shubham Grover

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM