从 C# WCF 服务返回具有动态维数的交错数组
我目前正在尝试创建一个服务,该服务将返回 C#/WCF 数据服务中 OLAP 多维数据集查询的结果。我这样做是为了获得对 OLAP 结果如何序列化、客户端如何进行身份验证/授权以及能够直接从网站中的 javascript 查询多维数据集的完整编程控制。
OLAP 查询的结果可能具有任意数量的维度(实际上最大介于 1 到 5 之间)。我遇到的问题是,我无法弄清楚如何首先创建动态维数的锯齿状数组,而不对我可能使用的每个维数的处理进行硬编码。所以第一个任务是:是否有一种优雅的方式在 C# 中创建动态维数的锯齿状数组?
一旦我有了这个动态维数数组,是否可以使用 DataContractJsonSerializer(或任何其他免费提供的 json 序列化器)将其序列化为 json。目标是将其序列化为一个类似于二维结果的对象:
{
"DimensionMemberCaptions" = [["Dim1 member1", "Dim2 member2"], ["Dim2 member1"], ["Dim2 member2"]],
"Data" = [[1, 2],
[3, 4]],
"FormatedData = [["1$", "2$"],
["3$", "4$"]]
}
其中 DimensionMemberCaptions 包含每个维度的标题(OLAP 成员名称),而 data/formateddata 是结果表。
我想避免编写自己的序列化函数,但随着时间的推移,它似乎更有吸引力——使用数组(多维数组而不是锯齿状数组)并编写我自己的 json 序列化程序,专门用于将 OLAP 输出序列化到流由 WCF REST 方法返回。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种解决问题的方法,该方法比我指定的问题更具体地针对 Adomd,但我认为可以应用相同的技术来解决这个问题,而不依赖于 Adomd。我选择使用Newtonsoft的Json序列化库(http://james.newtonking.com/projects/ json-net.aspx)。有了这个,我可以创建自己的“JsonConverter”来序列化 Adomd CellSet(基本上是多维 OLAP 查询的结果)。无论维数有多少,这都将起作用。
以及与之配套的 WCF Rest 服务:
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.
And the WCF Rest service to go with it: