删除 Asp.net Web 服务中 wsdl 中的字段
我正在使用模板引擎生成 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚遇到同样的问题。您可以通过将字段标记为
内部
来排除字段。Just hit the same problem. You can exclude fields by marking them as
internal
.如果您不想返回字段或属性,则不要将其包含在您返回的对象中!就这么简单。
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.