简体   繁体   中英

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?

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. But as the class can be regenerated any time i can't apply [XmlIgnore] to the fields.

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.

Just hit the same problem. You can exclude fields by marking them as 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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