我想知道如果我可以创建一个方法来返回使用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个字..继承。 :)。或者你可以创建一个具有成功/失败对象以及“正常”结果的类......一个响应对象。让客户对响应进行检查,以确定事情是否发生。 –