我想知道如果我可以創建一個方法來返回使用WCF客戶端捕獲不同的對象。我想用所有的異常細節來格式化一個引用類型,並通過WCF客戶端返回它。這是我想要實現的代碼。在WCF方法內返回不同的對象 - 不是拋出
[OperationContract]
PendingAccountDto createAccount(AccountActivationDto account);
我的接口
public PendingAccountDto createAccount(AccountActivationDto account)
{
try
{
DatabaseHelper.CheckForDatabaseAndCreate();
AccountDto newAccount = new PendingAccountDto(account);
response = DatabaseHelper.CreatePendingAccount(newAccount);
ActivationEmailer.SendEmail(newAccount);
PendingAccountDto pendingAccount = (PendingAccountDto)newAccount;
return pendingAccount;
}
catch(Exception ex)
{
ErrorMessageDto error = ExceptionBuilder.LogErrors(ex);
return error;
}
}
的實現現在在抓我想返回ErrorMessageDto對象,但該方法定義PendingAccountDto的返回類型。我希望wcf客戶端通過客戶端返回ErrorMessageDto,如果一個catch被觸發,但是,我不能這樣做,因爲返回類型期望PendingAccountDto。我查看了FaultCOntracts,但每個教程都將其顯示爲一個throw,並且我希望返回,以便可以通過客戶端查看該對象。有任何想法嗎?返回類型的泛型不適用於WCF方法。 任何意見將不勝感激。當我嘗試並設置
pendingAccount.Error = ExceptionBuilder.LogErrors(ex);
PendingAccountDto pendingAccount = new PendingAccountDto();
pendingAccount.Error = ExceptionBuilder.LogErrors(ex);
response.FailedTransaction(ex);
return pendingAccount;
1個字..繼承。 :)。或者你可以創建一個具有成功/失敗對象以及「正常」結果的類......一個響應對象。讓客戶對響應進行檢查,以確定事情是否發生。 –