简体   繁体   English

在Asp.net Web服务中删除wsdl中的字段

[英]Remove field in wsdl in Asp.net webservice

I'm generating dto classes with a template engine and would like to exclude some properties in an asmx webservice, what, if possible, is the best way to do this? 我正在使用模板引擎生成dto类,并且想排除asmx Web服务中的某些属性,如果可能的话,什么是最好的方法?

Ex: 例如:

[WebMethod]
public ProductPackages GetPackages()
{
   ProductPackages packages = new ProductPackages();
   packages.Packages.add(new PackageDTO());
   return packages;
}

The PackageDTO contains some properties that's not relevant for this service. PackageDTO包含一些与此服务无关的属性。 But as the class can be regenerated any time i can't apply [XmlIgnore] to the fields. 但是由于可以随时重新生成类,因此我无法将[XmlIgnore]应用于字段。

So I'm looking for a way to apply a "exclude list" without touching the actual class. 因此,我正在寻找一种无需触摸实际班级即可应用“排除列表”的方法。 Above is just an example, the template engine generates dto's for all tables in a given project, and I would like to be able to use them in services without needing to maintain a big bunch of nearly identical classes. 以上仅是一个示例,模板引擎为给定项目中的所有表生成dto,我希望能够在服务中使用它们,而无需维护大量几乎相同的类。

Just hit the same problem. 只是碰到同样的问题。 You can exclude fields by marking them as internal . 您可以通过将字段标记为internal来排除字段。

public class Order
{
    public double OrderPrice;
    internal double ProfitMargin;
    internal string TheTruthAboutThisCustomer;
}

If you don't want to return a field or property, then don't have it in the object you return! 如果您不想返回字段或属性,则不要在返回的对象中包含它! It's as simple as that. 就这么简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM