枚举未成功从 .NET2.0 客户端传递到 WCF 服务
我有一个 WCF 服务(.NET4.0)。客户端是.NET2.0。客户端传递到服务的枚举值始终设置为枚举默认值(这是第一个枚举成员)。
这是 .NET2.0 中的问题吗?有什么解决方法吗?
I have a WCF Service (.NET4.0). Client is in .NET2.0. Enum values passed by the client into the service are always set with enum default value (which is the first enum member).
Is this an issue in .NET2.0 ? Are there any workarounds ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所说,如果将其设置为 false,则您的字段将不会被序列化。不幸的是 false 是布尔字段的默认值,因此如果您忘记设置它会非常烦人。
如果您不喜欢此功能,那么您应该能够仅删除指定字段而不会产生任何后果。那么该字段将始终被序列化。
这些字段只会产生影响,因为您在 .NET 2 中使用 XmlSerializer。在 .NET 4 WCF 应用程序中,您使用的 DataContractSerializer 不具备此功能。
WCF 并未真正接收枚举的默认值。实际上,服务器上没有收到该枚举的任何信息。因此,未设置枚举,因此它仍然是默认值。
The <FieldName>Specified is a feature used by the XmlSerializer. I've been stung by this before. It seams everyone finds out about this feature in a similiarly painful manner.
As you say, if this is set to false then your field won't be serialised. Unfortunatly false is the default for a boolean field so it can very annoying if you forget to set it.
If you do not appreciate this feature then you should be able to just delete the <FieldName>Specified field without consequence. Then the field will always be serialized.
These fields only make a difference because you are using the XmlSerializer in .NET 2. In your .NET 4 WCF app you are using the DataContractSerializer which does not possess this feature.
The default value of the enum is not really received by WCF. Really nothing is received on the server for that enum. Consequently the enum is not set, so it remains the default value.