问题描述
大家好,
我是WCF和序列化的新手.我有一个关于datamember属性是否需要的问题.
I am new to WCF and serialization. I have a question regarding a datamember attribute isrequired.
我有几个数据成员
dm1,dm2,dm3
dm1, dm2 , dm3
仅在dm1具有特定值的情况下,我才希望为dm2设置IsRequired = true.
I want to set IsRequired = true for dm2 only in case dm1 has a specific value.
有可能吗?
谢谢
推荐答案
>>我只想在dm1具有特定值的情况下为dm2设置IsRequired = true
>> I want to set IsRequired = true for dm2 only in case dm1 has a specific value
否,这是不可能的,我们无法为IsRequired指定条件.
No, it is impossible, we could not specify condition for IsRequired.
您要验证dm2的值,还是要检查SOAP请求中是否存在dm2属性?如果要检查该值是否为null或为空,建议您尝试序列化回调,并且可以参考下面的链接以获取更多信息.
Do you want to validate the value for dm2, or want to check the dm2 attribute is exist in SOAP request? If you want to check the value is null or empty, I suggest you try Serialization Callback, and you could refer the link below for more information.
#WCF可扩展性–序列化回调
# WCF Extensibility – Serialization Callbacks
如果您需要检查属性是否存在,恐怕您需要尝试Message Inspectors,这有点复杂.
If you need to check the attribute exists, I am afraid you need to try Message Inspectors which is a little complex.
#WCF可扩展性–消息检查器
# WCF Extensibility – Message Inspectors
https://blogs.msdn.microsoft.com/carlosfigueira/2011/04/18/wcf-extensibility-message-inspectors/
最好的问候,
爱德华
这篇关于DataMember(IsRequired = true)取决于其他数据成员的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!