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

发布于 2024-08-11 16:08:57 字数 449 浏览 2 评论 0原文

我正在使用模板引擎生成 dto 类,并且希望排除 asmx Web 服务中的某些属性,如果可能的话,最好的方法是什么?

例如:

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

PackageDTO 包含一些与此服务不相关的属性。 但由于该类可以随时重新生成,因此我无法将 [XmlIgnore] 应用于字段。

所以我正在寻找一种方法来应用“排除列表”而不触及实际的类。 上面只是一个示例,模板引擎为给定项目中的所有表生成 dto,我希望能够在服务中使用它们,而不需要维护一大堆几乎相同的类。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍景流年 2024-08-18 16:08:57

刚刚遇到同样的问题。您可以通过将字段标记为内部来排除字段。

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

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;
}
提笔书几行 2024-08-18 16:08:57

如果您不想返回字段或属性,则不要将其包含在您返回的对象中!就这么简单。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文