我有一个奇怪的问题。我做了几个工作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);
}
如果我评论该行&#34; r = t.Select(x =&gt; new WrapImpianti(x,key))。ToList();&#34;,它可以...或者,至少,它返回一个空对象(因为我没有填充它)而没有循环。
为什么呢?它只调用我的类WrapImpianti的init方法......
这是班级
[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; }
}
}
为什么,如果我调用我的类init方法,它是否开始循环?然后,为什么它会返回ERR_CONNECTION_RESET?
答案 0 :(得分:0)
好的,这很有意思。解决方案在这里:
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为null并引发此错误。
它非常有用:我期望开发人员更容易看到这种类型的错误,而不是循环本身并得到匿名错误。
希望它对某人有用。 ;)