chao's profile清凉水都PhotosBlogListsMore Tools Help

Blog


    July 16

    WCF服务端发送自定错误

    [ServiceContract]

    [FaltException(typeof(CustomException))]

    CustomException是序列化数据

    ServiceDebugBehavior debug = new ServiceDebugBehavior();

    debug.IncludeExceptionDetailInFaults = fales;

    ServiceHost.Description.Behaviors.Add(debug)前要先清除自动生成Debug行为

    ServiceHost.Description.Behaviors.Remove<ServiceDebugBehavior>();因为会自动生成而Behaviors是一个KeyTypeOfCollection,因此无法容下两个同类型的对象。

     

    客户端截获用Cath(FaultException<CustomException> ex),注意这个ex的类型是FaultException,如果想要用自己的错误类型,需要这样:ex.Details,这样返回的就是CustomException了,之后就可以获取自定的信息和操作了。

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://ebakeshop.spaces.live.com/blog/cns!1A66D6C80502E805!362.trak
    Weblogs that reference this entry
    • None