Wcf中的异常处理 [英] Exception Handling in Wcf

查看:84
本文介绍了Wcf中的异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai friendz,
我为单个项目写了很多服务....我想在此服务中添加异常处理...我想显示用户友好消息..

现在我想使用以下异常之一..

hai friendz,
I wrote many services for single project....i want to put exception handling in this services...i wanna to display User Friendly messages..

now i want to use one of the following Exceptions..

System.ArgumentException
System.InvalidOperationException
System.NotImplementedException
System.NotSupportedException
System.ApplicationException



UserService.cs:



UserService.cs:

public class UserService:IUserService
   {
       /// <summary>
       /// Method to InsertUser
       /// </summary>
       /// <param name="Insertuserrequest"></param>
       /// <returns>InsertUserResponse</returns>
       public InsertUserResponse Insert(InsertUserRequest Insertuserrequest)
       {
           InsertUserResponse Insertuserresponse = null;
           try
           {
               Insertuserresponse = UserBLL.Insert(Insertuserrequest);
           }
           catch (BaseException ex)
           {
               throw new FaultException(ex.Summary);
           }

           return Insertuserresponse;
       }
}



UserBLL.cs:




UserBLL.cs:


public class UserBLL
    {
        public static  InsertUserResponse Insert(InsertUserRequest Insertuserrequest)
        {
            InsertUserResponse Insertuserresponse = new InsertUserResponse();
           
            try
            {
                if (Insertuserrequest.user.Password != null)
                {
                    Insertuserrequest.user.Password = EncryptPassword(Insertuserrequest.user.Password);
                    Insertuserresponse = UserRepository.Insert(Insertuserrequest);
                }
                else
                {
                    Insertuserresponse = UserRepository.Insert(Insertuserrequest);
                }
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Insertuserresponse;
        }      
    }



我该如何使用上述异常之一..

请帮帮我

在此先感谢



How can i use one of the above exception for this method..

Please help me

Thanks in advance

推荐答案

您必须在WCF中使用Fault合同作为自定义异常.
看看这个链接.
You have to use Fault contract for your custom exception in WCF.
Have a look on this link.


这篇关于Wcf中的异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆