不要在WCF service中使用TypedDataset或DataTable作为数据传输载体
Posted on 2007-05-26 16:37 江南白衣 阅读(24839) 评论(7) 编辑 收藏 举报讨论:
Using WCF for database operations
How to return datatable from a typed dataset using WCF service and Jun CTP ?
作为WCF的实践指导,这个原则在《Programming WCF Services》一书里也说明了:
Appendix C. WCF Coding Standard
C.4. Data Contracts
-
Use the DataMemberAttribute on properties or read-only public members only.
-
Avoid explicit XML serialization on your own types.
-
When using the Order property, assign the same value to all members coming from the same level in the class hierarchy.
-
Support IExtensibleDataObject on your data contracts.
-
Avoid setting IgnoreExtensionDataObject on the ServiceBehavior and CallbackBehavior attributes to TRue. Keep the default of false.
-
Do not mark delegates and events as data members.
-
Do not pass .NET-specific types, such as Type, as operation parameters.
-
Do not accept or return ADO.NET DataSet and DataTable (or their type-safe subclasses) from operations. Return a natural representation such as an array.
-
Suppress the generation of a generic type parameter hash code and provide a legible type name instead.
-
Avoid the /ct switch of SvcUtil or any other way of sharing an assembly type across the service boundary.
本着SOA的原则和传输效率之类的考虑,当然了,如果你的程序不跨平台(.NET---.NET)的话,DataSet之类的类型可以工作的很好。
BTW:《Programming WCF Services》这本书非常不错,除了对WCF技术的讲解之外还有大量的设计指导,不过目前只有英文版。园子里的Bruce Zhang正在翻译这本书。