![](/img/trans.png)
[英]Web service (ASMX) proxy creation and reference.cs file not generating
[英]How do I prevent web service from auto generating properties from fields in reference.cs
我遇到了一个问题,其中一个旧的win窗体应用程序中的某些代码正在使用对Web服务中的对象的反射来获取字段列表。 反射调用GetFields()。 在Web服务的数据对象中,我定义了如下字段:
public string PropertyAddress1;
public string PropertyAddress2;
public string PropertyCity;
public string PropertyCounty;
public string PropertyState;
在Win Forms应用程序中存在的当前版本的reference.cs中,字段看起来像这样。
public string PropertyAddress1;
public string PropertyAddress2;
public string PropertyCity;
public string PropertyCounty;
public string PropertyState;
一样吧?
好吧,我进入了Web服务的类并添加了另一个字段。 然后,我进入获胜表格应用程序,右键单击并单击更新Web参考。 重新生成代码后,reference.cs如下所示:
private string propertyAddress1Field;
private string propertyAddress2Field;
private string propertyCityField;
private string propertyCountyField;
private string propertyStateField;
public string PropertyAddress1 {
get {
return this.propertyAddress1Field;
}
set {
this.propertyAddress1Field = value;
}
}
/// <remarks/>
public string PropertyAddress2 {
get {
return this.propertyAddress2Field;
}
set {
this.propertyAddress2Field = value;
}
}
/// <remarks/>
public string PropertyCity {
get {
return this.propertyCityField;
}
set {
this.propertyCityField = value;
}
}
/// <remarks/>
public string PropertyCounty {
get {
return this.propertyCountyField;
}
set {
this.propertyCountyField = value;
}
}
/// <remarks/>
public string PropertyState {
get {
return this.propertyStateField;
}
set {
this.propertyStateField = value;
}
}
因为GetFields()不再返回任何内容,所以这摆脱了现有代码的行为。 我知道我可以将其交换到GetProperties(),但是该类已经具有已定义的属性,因此我不希望返回结果集。 我希望参考.cs将字段生成为字段,将属性生成为属性,而不是将字段转换为属性。 有什么办法可以在自动生成的字段的reference.cs中放置一些数据注释或其他某种形式的标志,以防止此行为?
您可以尝试手动更新reference.cs文件,以将属性替换为字段。 我愿意打赌,如果该引用尚未通过某种方式配置为使用字段而不是属性,那么以前的作者便会这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.