Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324946
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:12:03+00:00 2026-05-21T09:12:03+00:00

I’m currently trying create a service that will return results of a OLAP cube

  • 0

I’m currently trying create a service that will return results of a OLAP cube query in a C#/ WCF data service. I am doing this to gain complete programmatic control over how the OLAP results are serialized, how clients are authenticated/authorized and to be able to query cubes from javascript in a website directly.

The results from the OLAP queries may have any number of dimensions (realistically somewhere between 1 and 5 max). The problem I’m having is that I cannot figure out how to first create a jagged array of a dynamic number of dimensions without hard codding the handling of every number of dimensions I’ll possibly use. So the first quest is: is there an elegant way to create a jagged array of a dynamic number of dimensions in C#?

Once I have this array of dynamic number of dimensions, is it possible to then serialize this into json using DataContractJsonSerializer (or any other json serializer freely available). The goal is to serialize this into an object that looks something like this for 2-dimensional results:

{
  "DimensionMemberCaptions" = [["Dim1 member1", "Dim2 member2"], ["Dim2 member1"], ["Dim2 member2"]],
  "Data" = [[1, 2],
            [3, 4]],
  "FormatedData = [["1$", "2$"],
                   ["3$", "4$"]]
}

Where DimensionMemberCaptions contain the headers for each dimension (OLAP member names) and data/formateddata is a table of the results.

I would like to avoid writing my own serialization functions but its seeming more appealing as time goes on — using an Array (multi-dimensional array instead of jagged) and writing my own json serializer specifically for the purpose of serializing OLAP output to a Stream returned by a WCF REST method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:12:04+00:00Added an answer on May 21, 2026 at 9:12 am

    I found a way to solve my problem thats more specific to Adomd than my question specified, but I think the same technique could be applied to solve this without a dependency on Adomd. I choose to use Newtonsoft’s Json serialization library (http://james.newtonking.com/projects/json-net.aspx). With this I could create my own ‘JsonConverter’ to serialize a Adomd CellSet (basically the results from a mulitdimensional OLAP query). This will work regardless of the number of dimensions.

    public class CellSetConverter : JsonConverter
    {
    
        public override bool CanRead
        {
            get
            {
                return false;
            }
        }
    
        public override bool CanConvert(Type objectType)
        {
            if (objectType == typeof(CellSet))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }
    
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            CellSet cellSet = (CellSet)value;
            int cellCount = cellSet.Cells.Count;
            int[] axisCounts = new int[cellSet.Axes.Count];
            int[] currentIndex = new int[cellSet.Axes.Count];
            for (int i = 0; i < axisCounts.Length; i++)
            {
                axisCounts[i] = cellSet.Axes[i].Positions.Count;
            }
    
            for (int i = 0; i < cellSet.Axes.Count; i++)
            {
                writer.WriteStartArray();
            }
    
            for (int i = 0; i < cellCount; i++)
            {
                serializer.Serialize(writer, cellSet[currentIndex].Value);
                currentIndex = IncrementIndex(writer, currentIndex, axisCounts);
            }
        }
    
        string[] GetCaptions(CellSet cellSet, int[] index)
        {
            string[] captions = new string[index.Length];
            for (int i = 0; i < index.Length; i++)
            {
                Axis axis = cellSet.Axes[i];
                captions[i] = axis.Positions[index[i]].Members[0].Caption;
            }
    
            return captions;
        }
    
        int[] IncrementIndex(JsonWriter writer, int[] index, int[] maxSizes)
        {
            bool incremented = false;
            int currentAxis = 0;
            while (!incremented)
            {
                if (index[currentAxis] + 1 == maxSizes[currentAxis])
                {
                    writer.WriteEndArray();
                    index[currentAxis] = 0;
                    currentAxis++;
                }
                else
                {
                    for (int i = 0; i < currentAxis; i++)
                    {
                        writer.WriteStartArray();
                    }
    
                    index[currentAxis]++;
                    incremented = true;
                }
    
                if (currentAxis == index.Length)
                {
                    return null;
                }
            }
    
            return index;
        }
    }
    

    And the WCF Rest service to go with it:

    [ServiceContract]
    public class MdxService
    {
        const string JsonMimeType = "application/json";
        const string connectionString = "[Data Source String]";
        const string mdx = "[MDX query]";
    
        [OperationContract]
        [WebGet(UriTemplate = "OlapResults?session={session}&sequence={sequence}")]
        public Stream GetResults(string session, string sequence)
        {
            CellSet cellSet;
            using (AdomdConnection connection = new AdomdConnection(connectionString))
            {
                connection.Open();
                AdomdCommand command = connection.CreateCommand();
                command.CommandText = mdx;
                cellSet = command.ExecuteCellSet();
            }
    
            string result = JsonConvert.SerializeObject(cellSet, new CellSetConverter());
            WebOperationContext.Current.OutgoingResponse.ContentType = JsonMimeType;
            Encoding encoding = Encoding.UTF8;
            byte[] bytes = encoding.GetBytes(result);
            return new MemoryStream(bytes);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.