Thursday, May 17, 2012

Wcf Data Service fails selecting more than 8 properties (Columns) 'in select ($select) Query


This problem is caused because the way Microsoft and Oracle handles Empty String.  To solve this problem all you need to set "HandleNullStringsAsEmptyStrings = true" of oracle data driver as suggested by Devart team
Problem in detail
If you are developing WCF Data Service using Devart Data Driver and try to select more than 8 columns (properties ) in $select query it throws a null 

Stack Trace 
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
 <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code />
  <message xml:lang="en-US">An error occurred while processing this request.</message>
 <innererror>
  <message>Value cannot be null. Parameter name: value</message>
  <type>System.ArgumentNullException</type>
  <stacktrace>at System.Data.Services.WebUtil.CheckArgumentNull[T](T value, String parameterName) at System.Data.Services.Internal.ProjectedWrapper.set_PropertyNameList(String value) at lambda_method(Closure , Shaper ) at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext() at System.Data.Services.Internal.ProjectedWrapper.EnumeratorWrapper.MoveNext() at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService) at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description) at System.Data.Services.DataService`1.HandleRequest()</stacktrace>
  </innererror>
  </error>


Solution 
Just add one line in the service initialization code. 
public static void InitializeService(DataServiceConfiguration config)
        {
//  ….. Other code
            Devart.Data.Oracle.Entity.OracleEntityProviderServices.HandleNullStringsAsEmptyStrings = true;
        }


Root Cause 
This problem is combination of two issue , 
  1. WCF Runtime resolved projections ($Select) differently for more than 8 columns
  2. Oracle treats empty strings in varchar columns as null

References 
  1. http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/111a400b-9904-4808-a5fb-e8f24c6fe037
  2. http://forums.devart.com/viewtopic.php?t=19762
  3. http://blogs.planetsoftware.com.au/paul/archive/2011/01/28/ef4-part-9-tweaks-to-deal-with-oracle-and-wcf.aspx

No comments:

Post a Comment