WCF 自己调用两次或更多次,但前提是我保留代码行(我需要它)

WCF calls twice or more itself, but only if I keep a code line (I need it)

我有一个奇怪的问题。我做了几个工作 wcf。我已经更新了其中一个,似乎一切正常。

但是,如果我在浏览器中调用带有 get 的方法,我会得到 ERR_CONNECTION_RESET。调试它,我发现代码在循环,调用自己两次或三次,而调用只有一次。

代码确实和其他的差不多,但是有一点看不懂

为什么会循环?

这是我的方法的代码:

    public List<WrapImpianti> GetImpianto(string codret, string storeID, string hashedString, string outputType)
    {
        Utility.Logger("GetImpianto: start " + outputType);
        var md5 = new md5Manager();
        string key = "";
        IS_RETISTI retista = getRetista(codret);
        if (retista != null)
            key = retista.CHIAVEDES;
        List<WrapImpianti> r = new List<WrapImpianti>();
        //return r;
        if (md5.checkHashedInput(codret + storeID, hashedString, key))
        {
            try
            {
                using (var db = new AccessData.Entities())
                {
                    var t = db.IS_IMPIANTI.Where(x => x.STOREID == storeID && x.IDRET == retista.ID).ToList();
                    r = t.Select(x => new WrapImpianti(x, key)).ToList();
                }
                return r;
            }
            catch (Exception ex)
            {
                throw new WebFaultException<string>(ex.Message, HttpStatusCode.Conflict);
            }
        }
        else
            throw new WebFaultException<string>("Hash non corretto", HttpStatusCode.BadRequest);
    }

如果我注释行 "r = t.Select(x => new WrapImpianti(x, key)).ToList();",它会起作用...或者至少,它 return 是一个没有循环的空对象(因为我没有填充它)。

为什么?它只调用我的 class WrapImpianti...

的 init 方法

这是class

[DataContract]
    public class WrapImpianti
    {
        public WrapImpianti(){}
        private IS_IMPIANTI model;
        private string key;

        public WrapImpianti(IS_IMPIANTI model, string key)
        {
            this.model = model;
            this.key = key;
        }
        private string p_STOREID { get; set; }
        [DataMember]
        public string STOREID 
        { 
            get 
            {
                if (model == null)
                    return p_STOREID.ToSafeString();
                else
                    return this.model.STOREID.ToSafeString(); 
            }
            set { p_STOREID = value; }

        }
        private string p_CODICE { get; set; }
        [DataMember]
        public string CODICE
        {
            get
            {
                if (model == null)
                    return p_CODICE.ToSafeString();
                else
                    return this.model.CODICE.ToSafeString();
            }
            set { p_CODICE = value; }
        }
        private string p_CODRETE { get; set; }
        [DataMember]
        public string CODRETE
        {
            get
            {
                if (model == null)
                    return p_CODRETE.ToSafeString();
                else
                {
                    using (var db = new AccessData.Entities())
                    {
                        var pp = db.IS_RETISTI.FirstOrDefault(x => x.ID == this.model.IDRET);
                        if (pp != null)
                            return pp.CODICE;
                        else
                            return "";
                    }
                }
            }
            set { p_CODRETE = value; }
        }
        private string p_INDIRIZZO { get; set; }
        [DataMember]
        public string INDIRIZZO
        {
            get
            {
                if (model == null)
                    return p_INDIRIZZO.ToSafeString();
                else
                    return this.model.INDIRIZZO.ToSafeString();
            }
            set { p_INDIRIZZO = value; }
        }
        private string p_CITTA { get; set; }
        [DataMember]
        public string CITTA
        {
            get
            {
                if (model == null)
                    return p_CITTA.ToSafeString();
                else
                    return this.model.CITTA.ToSafeString();
            }
            set { p_CITTA = value; }
        }
        private string p_STATO { get; set; }
        [DataMember]
        public string STATO
        {
            get
            {
                if (model == null)
                    return p_STATO.ToSafeString();
                else
                    return this.model.STATO.ToSafeString();
            }
            set { p_STATO = value; }
        }
        private string p_COD_ESERCENTE { get; set; }
        [DataMember]
        public string COD_ESERCENTE
        {
            get
            {
                if (model == null)
                    return p_COD_ESERCENTE.ToSafeString();
                else
                    return this.model.COD_ESERCENTE.ToSafeString();
            }
            set { p_COD_ESERCENTE = value; }
        }
        private string p_TERMINAL_ID { get; set; }
        [DataMember]
        public string TERMINAL_ID
        {
            get
            {
                if (model == null)
                    return p_TERMINAL_ID.ToSafeString();
                else
                    return this.model.TERMINAL_ID.ToSafeString();
            }
            set { p_TERMINAL_ID = value; }
        }
        private string p_COL { get; set; }
        [DataMember]
        public string COL
        {
            get
            {
                if (model == null)
                    return p_COL.ToSafeString();
                else
                    return this.model.COL.ToSafeString();
            }
            set { p_COL = value; }
        }
        private string p_NOME { get; set; }
        [DataMember]
        public string NOME
        {
            get
            {
                if (model == null)
                    return p_NOME.ToSafeString();
                else
                    return this.model.NOME.ToSafeString();
            }
            set { p_NOME = value; }
        }
        private string p_CAP { get; set; }
        [DataMember]
        public string CAP
        {
            get
            {
                if (model == null)
                    return p_CAP.ToSafeString();
                else
                    return this.model.CAP.ToSafeString();
            }
            set { p_CAP = value; }
        }
        private string p_TELUFF { get; set; }
        [DataMember]
        public string TELUFF
        {
            get
            {
                if (model == null)
                    return p_TELUFF.ToSafeString();
                else
                    return this.model.TELUFF.ToSafeString();
            }
            set { p_TELUFF = value; }
        }
        private string p_TELCELL { get; set; }
        [DataMember]
        public string TELCELL
        {
            get
            {
                if (model == null)
                    return p_TELCELL.ToSafeString();
                else
                    return this.model.TELCELL.ToSafeString();
            }
            set { p_TELCELL = value; }
        }
        private string p_NOTE { get; set; }
        [DataMember]
        public string NOTE
        {
            get
            {
                if (model == null)
                    return p_NOTE.ToSafeString();
                else
                    return this.model.NOTE.ToSafeString();
            }
            set { p_NOTE = value; }
        }
        private string p_PIVA { get; set; }
        [DataMember]
        public string PIVA
        {
            get
            {
                if (model == null)
                    return p_PIVA.ToSafeString();
                else
                    return this.model.PIVA.ToSafeString();
            }
            set { p_PIVA = value; }
        }
        private string p_CODICEFISCALE { get; set; }
        [DataMember]
        public string CODICEFISCALE
        {
            get
            {
                if (model == null)
                    return p_CODICEFISCALE.ToSafeString();
                else
                    return this.model.CODICEFISCALE.ToSafeString();
            }
            set { p_CODICEFISCALE = value; }
        }
        private string p_GESTORE { get; set; }
        [DataMember]
        public string GESTORE
        {
            get
            {
                if (model == null)
                    return p_GESTORE.ToSafeString();
                else
                {
                    using (var db = new AccessData.Entities())
                    {
                        return db.IS_GESTORI.FirstOrDefault(x => x.ID == this.model.IDGES).CODICE.ToSafeString();
                    }
                }
            }
            set { p_GESTORE = value; }
        }
        private string p_PROPRIETARIO { get; set; }
        [DataMember]
        public string PROPRIETARIO
        {
            get
            {
                if (model == null)
                    return p_PROPRIETARIO.ToSafeString();
                else
                {
                    using (var db = new AccessData.Entities())
                    {
                        return db.IS_PROPRIETARI.FirstOrDefault(x => x.ID == this.model.IDPRP).CODICE.ToSafeString();
                    }
                }
            }
            set { p_PROPRIETARIO = value; }
        }
    }

为什么,如果我调用 class init 方法,它会开始循环吗?然后,为什么 return ERR_CONNECTION_RESET?

好的,这很有趣。解决方案在这里:

    public string PROPRIETARIO
    {
        get
        {
            if (model == null)
                return p_PROPRIETARIO.ToSafeString();
            else
            {
                using (var db = new AccessData.Entities())
                {
                    return db.IS_PROPRIETARI.FirstOrDefault(x => x.ID == this.model.IDPRP).CODICE.ToSafeString();
                }
            }
        }
        set { p_PROPRIETARIO = value; }

在我的自定义类中..有时,IDPRP 为空并引发此错误。

非常有趣:我原以为这种类型的错误对开发人员来说更明显,而不是循环本身并得到一个匿名错误。

希望它对某人有用。 ;)