[AX]AX2012 SSRS报表使用Report Data Method

在AX2012的SSRS报表中可以使用c#或者Visual basic .net编写report data method来获取和操作数据,由report data method返回的数据可以用在报表的表达式中,也可以用作dataset的数据源。

使用Report data method首先需要创建AX model工程,在工程中添加一个报表,双击打开报表,在报表的Data methods节点下右键“Add data method”,设置其名称,右键点击这个添加的data method在菜单中选择“View code”,Visual studio会自动创建一个C#的工程,工程名称为“报表名称.BusinessLogic”,并定义一个和报表名称相同的类,同时自动添加一个DataMethod特性标注的静态方法,类似:

public partial class TestDataMethodReport
{[DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")]public static string DataMethod1(){throw new NotImplementedException("The method or operation is not implemented.");}
}

默认是使用C#工程,要使用Visual basic需要手工设置报表的属性“Data method library”为一个预先添加到AOT中的visual basic的工程,然后就可以在这个VB工程中添加相应的report data method类和方法。

如果要使用report data method作为dataset的数据源,report data method必须返回值类型必须是IEnumerable<DataRow>或者DataTable。返回的数据量可能比较的多,建议使用yield return 返回一个IEnumerable<DataRow>的数据,这要比返回DataTable效率高。report data method可以有参数,这些参数和报表dataset的参数想对应。由于类的名称和报表名称要求相同,所以一个reprot data method只能用在一个报表中,不能被多个报表共享。下面是一个report data method返回数据集的例子:

[DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")]
public static IEnumerable<DataRow> CreateInventoryItemByRow()
{// Define a data table.DataTable table = new DataTable();table.Columns.Add(new DataColumn("ItemID", Type.GetType("System.Int32")));table.Columns.Add(new DataColumn("Name", Type.GetType("System.String")));table.Columns.Add(new DataColumn("Description", Type.GetType("System.String")));table.Columns.Add(new DataColumn("Cost", Type.GetType("System.Decimal")));table.Columns.Add(new DataColumn("SellingPrice", Type.GetType("System.Decimal")));DataRow row = null;row = table.NewRow();row.ItemArray = new object[] { 1734, "Clamp", "Workbench Clamp", 12.48, 17.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 1983, "Saw", "Wooden Handle Saw", 7.89, 11.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 6728, "Screwdriver", "Standard Screwdriver", 2.75, 3.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 4920, "Nails", "Roofing Nails 5lbs", 12.45, 15.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 4829, "Tape Measure", "25 ft Tape Measure", 12.87, 16.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 2893, "Nails", "Finish Nails", 3.90, 5.99 };yield return row;
}

 要在报表中使用report data method作为数据源,首先需要编译包含report data method的bussiness logic工程并添加到AOT中。在报表中新建一个dataset,dataset的数据源选择Dynamics AX,Data source type选择bussiness logic,点击Query属性的...按钮就可以选择相应的report data method。包含report的ax model工程也需要编译后添加到AOT,否则也是看不到这个report data method的。

 Data report method还可以用在报表的一些表达式中,比如AX自带的Ax model工程CaseReports中用到了这样一个data method:

public partial class Case_MyCases
[DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")]
public static string GetDefaultColorDark(int index)
{return ColorHelper.GetDefaultColorDark(index);
}

报表chart图形有使用这个方法作为数据系列的颜色:

=GetDefaultColorDark(0)

Report data method使用.net编写可以读取AX以为的数据源,也可以使用custom service来从X++方法获取数据,X++被编译为.net CIL后由custom service宿主供托管代码调用。先在AX中定义一个X++的类:

public class HelloWorld
{
}
[SysEntryPointAttribute(true)]
public str printHelloWorld()
{    return "Hello World";
}

在AOT的service节点下新建一个service,设置Name为MyService,ExternalName为HelloWorldService,选择Class为HelloWorld。在MyService下添加一个service operations,选择方法printHelloWorld。

在AOT的Service group下添加一个名为MyServiceGroup的组,把MyService拖到这个组中,部署MyServiceGroup。

 回到Visual studio中的bussinesslogic工程,在工程的reference下添加一个service reference,服务URL类似:http://[machinename]:8101/DynamicsAx/Services/MyServiceGroup。在列出的服务中选择MyServiceGroup添加到工程,删除工程中的app.config文件,编译时app.config重新生成。在bussiness logic工程添加一个新的report data method来测试,注意在cs文件中using相应的service reference:

public static string HelloWorldDataMethod()
{// Create an instance of the client proxy class that connects to the service exposed in Microsoft Dynamics AX.var client = AxServiceManagement.CreateServiceClient<HelloWorldServiceClient>("MyServiceGroup");// Call the "printHelloWorld" operation on the service - passing the company that you are testing in.CallContext context = new CallContext();context.Company = "ceu";string returnedValue = client.printHelloWorld(context);// Return the result.return returnedValue;
}

在report上新建一个precision的design,添加一个textbox到design,设置其value属性为表达式:

=HelloWorldDataMethod()

预览报表textbox显示#error,VS的输出中有警告信息:

Warning 7 The Value expression for the textrun ‘Textbox1.Paragraphs[0].TextRuns[0]’ contains an error: Unable to find matching endpoint configuration for the passed contract 'HelloWorldService' and port name 'MyServiceGroup' TestDataMethodReport.PrecisionDesign1 [Preview] 0 0

 新建了一个控制台的工程来测试这个AIF service,却是能正常得到结果的。不知道问题出在哪里,来回删除service reference重建运行报表也是一样的。意外重启了服务器,再运行报表正常了,...问题又出在那个哪个缓存没更新?!问题还不算完,在VS里预览报表没有问题了,但是在AX通过menu item运行报表或者在SQL report service的页面上运行报表又是一样的错误结果,真是无语啊。查看windows日志有这样的错误:

Object Server 01: An error has occurred in the services framework. Method: AifMessageInspector::AfterReceiveRequest. Error: System.ServiceModel.FaultException: Failed to logon to Microsoft Dynamics AX.
at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.InitializeSession()
at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.InitializeContext()
at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.Attach(OperationContext owner)
at System.ServiceModel.ExtensionCollection`1.InsertItem(Int32 index, IExtension`1 item)
at System.Collections.Generic.SynchronizedCollection`1.Add(T item)
at Microsoft.Dynamics.Ax.Services.AifMessageInspector.AfterReceiveRequest(Message& request, IClientChannel channel, InstanceContext instanceContext)

貌似是什么权限类的错误,google发现不少人都遇到这个错误(http://community.dynamics.com/product/ax/f/33/p/64670/158445.aspx#158445),有人说要把report service的账号添加到windows access authorized group和pre-windows 2000 compatiable group,还有人说要在ax client configuration中刷新下配置,不知道什么时候还出现了这样的错误:

Unable to write the generated WCF configuration to local storage. The generated WCF configuration will be used from memory. The contents of the new configuration are written to the following temp file: C:\Users\AOS\AppData\Local\Temp\Microsoft.Dynamics.AX.Framework.Services.Client.Configuration.ClientConfigurationInternal.log.

AOS是我的AOS service的账户,也是SQL report service的账户,好像是要被配置文件写到注册表被拒绝而使用内存中的配置信息,不知道是不是这个原因。还有人说升级了AX kernel,错误消失了,就这样放着吧,以后再说,休息一下,休息一下。

这个Report data method可以用在报表的表达式中,更多内容参见http://msdn.microsoft.com/en-us/library/cc587341.aspx

 

转载于:https://www.cnblogs.com/duanshuiliu/archive/2012/08/23/2651904.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/463434.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HIVE和HBASE区别

转载&#xff1a;https://www.cnblogs.com/justinzhang/p/4273470.html 1. 两者分别是什么&#xff1f; Apache Hive是一个构建在Hadoop基础设施之上的数据仓库。通过Hive可以使用HQL语言查询存放在HDFS上的数据。HQL是一种类SQL语言&#xff0c;这种语言最终被转化为Map/Re…

php调试

今天在使用php 的session 的时候&#xff0c;出现了以前就遇见但是又解决不了的问题&#xff0c;在页面上出现如下提示&#xff1a; Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\php…

C 结构体

C 结构体C 数组允许定义可存储相同类型数据项的变量&#xff0c;结构是 C 编程中另一种用户自定义的可用的数据类型&#xff0c;它允许您存储不同类型的数据项。结构用于表示一条记录&#xff0c;假设您想要跟踪图书馆中书本的动态&#xff0c;您可能需要跟踪每本书的下列属性&…

lightoj1259 线性筛的另一种写法 v变成bool标记数组

也是用线性筛&#xff0c;但是v用int会爆&#xff0c;所以这个线性筛用的是另外一种写法 #include<cstdio> #include<cmath> #include<queue> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using na…

Redis基数统计之HyperLogLog小内存大用处

转载&#xff1a;https://blog.csdn.net/azhegps/article/details/71158952 我们一直都知道&#xff0c;redis几大常用数据结构&#xff0c;字符串、散列、列表、集合、有序集合。其实后来Redis做了很多补充&#xff0c;其中之一就是HyperLogLog&#xff0c;另外的还有GEO&…

matlab中的qr函数

转自&#xff1a;https://blog.csdn.net/qq278672818/article/details/62038630 实数矩阵A的QR分解是把A分解为A QR这里的Q是正交矩阵&#xff08;意味着QTQ I&#xff09;而R是上三角矩阵。类似的&#xff0c;我们可以定义A的QL, RQ和LQ分解。更一般的说&#xff0c;我们可以…

(String) 和 String.valueOf() 两种字符串转换的区别

使用 String.valueOf() 进行数据转换&#xff0c;如果被转换的数据为 null, 则这种方法将返回一个 "null" 字符串 &#xff08;String&#xff09; 方法进行转换时&#xff0c;如果被转换的数据为 null, 则返回 null 对象而不是一个 "null" 字符串。转载于…

利用有名管道实现进程间的通信

1 /*****************************************************************2 * Copyright (C) 2018 FBI WARNING. All rights reserved.3 * 4 * 文件名称&#xff1a;fifo_write.c5 * 创 建 者&#xff1a;constantine6 * 创建日期&#xff1a;2018年02月26日7 * 描 …

为什么分布式一定要有redis,redis的一些优缺点

1、为什么使用redis 分析:博主觉得在项目中使用redis&#xff0c;主要是从两个角度去考虑:性能和并发。当然&#xff0c;redis还具备可以做分布式锁等其他功能&#xff0c;但是如果只是为了分布式锁这些其他功能&#xff0c;完全还有其他中间件(如zookpeer等)代替&#xff0c;…

Google protobuf使用技巧和经验

Google protobuf是非常出色的开源工具&#xff0c;在项目中可以用它来作为服务间数据交互的接口&#xff0c;例如rpc服务、数据文件传输等。protobuf为proto文件中定义的对象提供了标准的序列化和反序列化方法&#xff0c;可以很方便的对pb对象进行各种解析和转换。以下是我总结…

show部分书...

继续购入中 转载于:https://www.cnblogs.com/Clingingboy/archive/2009/06/09/1499816.html

linux 中用PPA安装软件

一般来说 PPA 提供了三条命令&#xff0c;如下面的命令&#xff1a; sudo apt-get sudo apt-get update sudo apt-get install 其中&#xff0c;第一行的代码后面加上 获得安装软件的地址 第二行为更新系统源地址 第三行为安装软件

HTTP_POST———使用mysql_udf与curl库完成http_post通信模块(mysql_udf,multi_curl,http,post)...

HTTP_POST———使用mysql_udf与curl库完成http_post通信模块&#xff08;mysql_udf,multi_curl,http,post&#xff09; 这个模块其目前主要用于xoyo江湖的sns与kingsoft_xoyo自主研发的TCSQL数据库做数据同步&#xff0c;当有feed插入sns数据库&#xff0c;使用触 发器调用该模…

LSM树存储模型

LSM&#xff08;log-structed-merge-tree&#xff09; leveldb和rocksdb底层使用LSM树做存储引擎&#xff0c;LSM树使用skiplist做索引&#xff0c;他们先将数据写入内存中&#xff0c;按照key进行划分&#xff0c;定期的merge写入到磁盘中&#xff0c;合并后数据写入下一层le…

js-图片预加载

//图片预加载 //闭包模拟局部作用于(function($){function Preload(imgs,options){this.imgs (typeof imgs string) ? [imgs]:imgs;this.opts $.extend({},Preload.DEFAULTS,options);if(this.opts.order ordered){//有序加载this._ordered();}else{//无序加载this._unord…

LevelDb实现原理

原文地址&#xff1a;http://www.samecity.com/blog/Index.asp?SortID12&#xff0c; 最近由于工作上的需求&#xff0c;需要用到leveldb&#xff0c;因此转载此文章用于以后的查询使用。 LevelDb日知录之一&#xff1a;LevelDb 101 说起LevelDb也许您不清楚&#xff0c;但是…

发现几个常用的asp.net MVC Helper 源码

AspNetMvc.DbC.zipXmlSiteMap.zipXhtmlHelper.zipTreeView.zipQuickMenu.zipRotator_v1-1.zipRSSReader.zipFormValidation.zip转载于:https://www.cnblogs.com/nick4/archive/2009/06/10/1500284.html

排序 八种经典排序算法

排序(Sorting) 是计算机程序设计中的一种重要操作&#xff0c;它的功能是将一个数据元素(或记录)的任意序列&#xff0c;重新排列成一个关键字有序的序列。 我整理了以前自己所写的一些排序算法结合网上的一些资料&#xff0c;共介绍8种常用的排序算法&#xff0c;希望对大家能…

Redis使用过程出现类型转换异常问题- 20190220

问题描述&#xff1a; 使用redis过程中&#xff0c;出现类型转换异常问题&#xff0c;出现在存数据和取数据时。而且相同代码在本地测试无异常&#xff0c;而提交到测试环境&#xff0c;则会出现问题。 问题原因&#xff1a; 最后定位到&#xff0c;原因在使用redis存取数据时&…

表达式求值Spring.Expressions

简介Spring.Expressions命名空间可以用一种强大的表达式语言在运行时操作对象。这种语言可以读写属性值、调用方法、访问数组/集合/索引器的元素、进行算术和逻辑运算&#xff0c;同时支持命名变量&#xff0c;并且能够通过名称从IoC容器获取对象。 在Spring.NET中&#xff0c…