[英]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.