验证 WCF 数据协定集合中的元素
我们有一个 WCF 服务,它使用 Microsoft.Practices.EnterpriseLibrary.Validation 并接收一个如下所示的对象(简化的):
[DataMember]
[NotNullValidator]
public string Name { get; set; }
[DataMember]
public IList<Appointment> Appointments { get; set; }
Appointment DataContract 可能如下所示:
[DataMember]
[NotNullValidator]
public string Description { get; set; }
现在的问题是 Name 属性的验证似乎有效,但 Description 却无效未验证。因此,您不能传递具有空名称的请求,但您可以传递具有名称和空描述的约会列表的请求。
WCF 不验证 DataContract 中集合的元素是否正常?
We have a WCF service that uses Microsoft.Practices.EnterpriseLibrary.Validation and receives an object like so (simplified):
[DataMember]
[NotNullValidator]
public string Name { get; set; }
[DataMember]
public IList<Appointment> Appointments { get; set; }
The Appointment DataContract could look like:
[DataMember]
[NotNullValidator]
public string Description { get; set; }
Now the problem is that the validation of the Name property seems to work, but the Description isn't validated. So you can't pass a request with an empty Name, but you can pass a request with a Name and a list of Appointments with empty Descriptions.
Is it normal that WCF doesn't validate the elements of a collection in a DataContract?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我们通过添加 SelfValidation 解决了这个问题:
Well, we solved it by adding SelfValidation: