Tuesday, April 24, 2012

WCF Data Service (OData) Best Practices ,Dos and Don`t dos

This Post consolidated my experience of working with WCF Data Service on server side, may be someone else can get benefited of it.
Alternative Titles
WCF Data Service (OData) Recommended Practices
WCF Data Service Dos and Don`t dos
  1. Avoid using "ExecuteStoreCommand" because it cause several problem in serialization and as a result $select query will fail on any property other than string Read More...
  2. Prefer creating separate project for data models that will be easier to ship.
  3. Must add a service operation 'Version' that should display service version as XML response it will help automated clients to dynamically modify there behavior.
  4. Avoid using custom parameters that will not be passed to next page and will cause problem in case of paging Read More...  
  5. If using external entity provider like Devart for Oracle then make sure that you have Unicode=True setting turned on for global application several provider have it off by default. Read More...
  6. Prefer handling exception centrally at service level and throw a grace full error massage for known issues with your implementations.
  7. Avoid using large and complex queries in <DefiningQuery> tag of storage model
  8. if you have extra fields in your conceptual model then initialize them using <QueryView> of conceptual model, it can also be used for entity level joins.
  9. If your project have multiple service classes then prefer to keep common configuration code in a separate class and override as required.
  10. Always add cross site scripting support to support client like silver light, all you need to add a crosssite.xml file to service root.
  11. Must add JSONP support to service via get protocol because it is well accepted on device world.
  12. Configure your model to proper display of data over the browser as feeds.
  13. Plan versioning  in early phase   of development
  14. for authentication Override OnStartProcessingRequest  add add your custom authentication logic
  15. For authorization use change/ query interceptors
  16. Use reflection provider for exposing your custom classes without using EF
  17. Write custom data provider if you need to have good control of data service and want to use data service with multiple data sources
  18. Be carefull if using  ObjectMaterialized even because it does not get fired in case of $select (projection) query. Read More...
  19. Avoid Creating Service Operation because they are not well supported by  Data Service Client libraries http://msdn.microsoft.com/en-us/library/hh230677.aspx 
  20. If creating Service Operation then prefer creating GET method because POST is not supported by client library. 
  21. If creating EDMX from a view make sure the keys it is generating is correct and try to keep minimum number of columns in key. This will solve several run time problems.EDMX generator is not good in figuring keys for views and just creates a key by picking all the column that marked as NOT_NULL here is an example
  22. Avoid building a Data Service (EDMX) with no Primary Key in Table or Inferred Primary key it may lead you strange bugs that will be hard to find Read more...
Reference Video
Best Practices: Creating OData Services Using Windows Communication Foundation (WCF) Data Services


No comments:

Post a Comment