Geeks With Blogs
Josh Reuben

You cant pass MultiD arrays accross the wire using WCF - you need to pass jagged arrays.

heres 2 extension methods that will allow you to convert prior to serialzation and convert back after deserialization:

        public static T[,] ToMultiD<T>(this T[][] jArray)
        {
            int i = jArray.Count();
            int j = jArray.Select(x => x.Count()).Aggregate(0, (current, c) => (current > c) ? current : c);
           
 
            var mArray = new T[i, j];
 
            for (int ii = 0; ii < i; ii++)
            {
                for (int jj = 0; jj < j; jj++)
                {
                    mArray[ii, jj] = jArray[ii][jj];
                }
            }

            return mArray;
        }

        public static T[][] ToJagged<T>(this T[,] mArray)
        {
            var cols = mArray.GetLength(0);
            var rows = mArray.GetLength(1);
            var jArray = new T[cols][];
            for (int i = 0; i < cols; i++)
            {
                jArray[i] = new T[rows];
                for (int j = 0; j < rows; j++)
                {
                    jArray[i][j] = mArray[i, j];
                }
            }
            return jArray;
        }

enjoy!

Posted on Wednesday, March 16, 2011 1:31 PM | Back to top


Comments on this post: WCF Operations and Multidimensional Arrays

# re: WCF Operations and Multidimensional Arrays
Requesting Gravatar...
There is something very useful that we can learn from here. - Paradise Home Improvement Charlotte
Left by Ema Wayne on Dec 22, 2016 11:37 AM

Your comment:
 (will show your gravatar)


Copyright © JoshReuben | Powered by: GeeksWithBlogs.net