我們使用的是MSCRM Dynamics,我們試圖讓一個特定用戶的所有孩子。 (一個用戶有一個經理,經理有'子女'。)以下工作,但如果用戶沒有子女則拋出異常。這可能起初似乎是合乎邏輯的,但爲什麼不只是返回一個空集呢?而且所有的東西都會拋出一個帶有「Invalid Argument」(這是錯誤的)神祕消息的SoapException,並且.Detail.InnerText會顯示「0x80040203爲ConditionOperator.In傳遞的值是空的平臺」。如果你看看相應的Response類,它有一個集合 - 爲什麼不把它留空?CRM:讓孩子在沒有孩子的情況下拋出異常
// Create the request object.
RetrieveAllChildUsersSystemUserRequest retrieve =
new RetrieveAllChildUsersSystemUserRequest();
// Create the column set object that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();
cols.EntityName = "systemuserid";
// Set the column set.
retrieve.ColumnSet = cols;
// Set the ID of the parent user.
retrieve.EntityId = context.UserId;
RetrieveAllChildUsersSystemUserResponse retrieved =
new RetrieveAllChildUsersSystemUserResponse();
/// Execute the request.
/// Catches if user does not have children
/// (Check to see if user is manager)
try
{
retrieved =
(RetrieveAllChildUsersSystemUserResponse)crmService.Execute(retrieve);
}
catch (System.Web.Services.Protocols.SoapException e)
{
throw new Exception(string.Format("{0}", e.Detail.InnerText));
}
我們正在吞嚥所有SoapExceptions,我真的覺得這是一個糟糕的解決方案。如果不能找到更好的解決方案,我將不得不在表達式中挖掘一下,看看我能否更好地隔離這種情況。 – Thanatos 2009-06-23 23:13:35