[英]I have this error 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.