为什么我被迫用数据契约属性来装饰这些类?
这确实令人困惑,但几乎没有任何原因,我曾经工作的 WCF 服务迫使我用 DataContract 属性装饰两个类,即使我没有将它们作为方法或 asp.net 中的返回值传递回作为参数之一的方法。
简而言之,它们不需要序列化。我能看到的唯一原因是它们是作为成员变量存储在已用 [DataContract] 属性修饰的类中的对象?它们是对象中的新对象,正在传递回我的 WCF 方法...
有人知道为什么会突然发生这种情况吗?
This is really confusing but almost for no reason my once working WCF service is forcing me to decorate two classes with the DataContract attribute even though I am not passing them back as a return value in a method or asp.net as one of the parameters to the method.
In short they do not need to be serialized. The only reason I can see is that they are objects stored as member variables within a class that has been decorated with the [DataContract] attribute? They are new objects within the object that im passing back to my WCF methods...
Anyone know why this would suddenly happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WCF 从 .net 3.5 开始支持 POCO,
但是如果您想采用 POCO 方式,那么您的服务直接或间接公开的任何类都不必使用 DataContract 属性进行修饰。
http://msdn.microsoft.com/en-us/library/dd456853.aspx
WCF supports POCO from .net 3.5
But if you want to go the POCO way then NONE of the classes directly or indirectly exposed by your service must be decorated with the DataContract attribute.
http://msdn.microsoft.com/en-us/library/dd456853.aspx