zoukankan      html  css  js  c++  java
  • WCF 抛出FaultException<T>异常

    1. DataContract   - new class FaultMessage
        [DataContract]
        public class FaultMessage
        {
            [DataMember]
            public string ErrorCode { get; set; }

            [DataMember]
            public string Message { get; set; }
        }

    2. WCF Service
        try
        {
            return XXX;
        }catch(Exception ex)
        {
            FaultMessage faultMessage = new FaultMessage();
            faultMessage.ErrorCode = "ErrorCode ";
            faultMessage.Message = ex.Message;
            throw new FaultException<FaultMessage>(faultMessage);
        }

    3. ServiceContract    -- add [FaultContract(typeof(FaultMessage))]
        [ServiceContract]
        public interface IGameContract
        {
            [OperationContract]
            [FaultContract(typeof(FaultMessage))]
            IList<DungeonInfo> GetDungeonList();
            [OperationContract]
            [FaultContract(typeof(FaultMessage))]
             ...
        }

    4.UI
        try
        {
            Service1.ServiceClient client = new Service1.ServiceClient()
            XXXX
        }
        catch (FaultException<Service1.FaultMessage> ex)
        {
            LabelMsg.Text = string.Format("ErrorCode:{0}\n Message:{1}", ex.Detail.ErrorCode, ex.Detail.Message);
        }

  • 相关阅读:
    JSOIWC2019游记
    基础网络流题单
    【题解】Luogu P2472 [SCOI2007]蜥蜴
    【题解】Luogu P2057 [SHOI2007]善意的投票
    凸包略解
    【题解】Luogu P4324 [JSOI2016]扭动的回文串
    【题解】Luogu P4054 [JSOI2009]计数问题
    kruscal重构树略解
    【题解】bzoj 4478 [Jsoi2013]侦探jyy
    【题解】4465 [Jsoi2013]游戏中的学问
  • 原文地址:https://www.cnblogs.com/webglcn/p/2479992.html
Copyright © 2011-2022 走看看