Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A reporting service using SOAP calls passing XML to a Data Extension

, 19 Oct 2005 CPOL
Demostrates how to render a report by passing XML to a data extension via SOAP calls.
RSDataExtensionXml_demo.zip
RSTestApp
CustomDataExtension
CustomDataExtension.csproj.user
Web References
BusinessService
BusinessData.disco
BusinessData.wsdl
Reference.map
Global.asax
RsReportViewer
AwReportViewer.suo
Design
vssver.scc
RsReportViewer.csproj.user
Web References
RS
Reference.map
ReportService.wsdl
RSTestApp.csproj.webinfo
RSTestReports
Northwind.rds
Northwind.udl
Report1.rdl
Report1.rdl.data
RSTest.rptproj.user
RSTestReports.rptproj
RSTestReports.rptproj.user
Sales Order Detail.rdl
Sales Order Detail.rdl.data
Territory Sales Drilldown.rdl
Territory Sales Drilldown.rdl.data
RSTestWS
Global.asax
RSTestWS.csproj.webinfo
temp
Web References
ReportServer
Reference.map
ReportService.wsdl
// File: DataSetDataReader.cs

using System;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Xml;

using Microsoft.ReportingServices.DataProcessing;

namespace CustomDataExtension
{
	/// <summary>
	/// Description :	A Data Processing Extension IDataReader
	/// </summary>
	public class DataSetDataReader : IDataReader 
	{
		private System.Data.DataSet	_dataSet;
		private int	_currentRow;

		public DataSetDataReader(string sXml) 
		{
			try
			{
				BusinessService.BusinessData BusWS = new BusinessService.BusinessData();
				this._dataSet = BusWS.GetReportDataSet(sXml);
				
				//set the current row to one before the first
				_currentRow = -1;
			}
			catch(Exception ex)
			{
				throw new Exception("Error calling web service XML: " + sXml, ex);
			}
		}

		/// <summary>
		/// Moves to the first or next row
		/// </summary>
		/// <returns>True if more data present, false if done</returns>
		public Boolean Read() 
		{
			bool bRet = false;
			int nRowCount = 0;
			try
			{
				Debug.Assert (this._dataSet != null, "Internal Error: this.dataSet should not be null");
				if (this._dataSet != null)
				{
					this._currentRow ++;
					nRowCount = this._dataSet.Tables[0].Rows.Count;
					if (this._currentRow >= nRowCount) 
					{
						//Debug.WriteLine("DataReader: Done with all rows");
						bRet = false;
					} 
					else 
					{
						//Debug.WriteLine("DataReader: Moved to row " + this._currentRow);
						bRet = true;
					}
				}
			}
			catch (Exception ex)
			{
				Debug.WriteLine("DataReader failed. " + ex.Message);
			}
			return bRet;
		}

		/// <summary>
		/// Retrieves the number of fields per row
		/// </summary>
		public int FieldCount 
		{
			get 
			{
				return(this._dataSet.Tables[0].Columns.Count);
			}
		}

		/// <summary>
		/// Retrieves the name of a field
		/// </summary>
		/// <param name="Index">The index of the field</param>
		/// <returns>The name of the specified field</returns>
		public String GetName(int Index) 
		{
			return(this._dataSet.Tables[0].Columns[Index].ColumnName);
		}

		/// <summary>
		/// Retrieves the data type of a field
		/// </summary>
		/// <param name="Index">The index of the field</param>
		/// <returns>The data type of the specified field</returns>
		public Type GetFieldType(int Index) 
		{
			return(this._dataSet.Tables[0].Columns[Index].DataType);
		}

		/// <summary>
		/// Gets the value of a field on the current row
		/// </summary>
		/// <param name="Index">The index of the field</param>
		/// <returns>The value of the column</returns>
		public Object GetValue(int Index) 
		{
			return(this._dataSet.Tables[0].Rows[this._currentRow][Index]);
		}

		/// <summary>
		/// Retrieves the ordinal of a field based on the field name
		/// </summary>
		/// <param name="Name">The name of the field</param>
		/// <returns>The ordinal of the specified field</returns>
		public int GetOrdinal(string Name) 
		{
			//Debug.WriteLine("DataReader.GetOrdinal(" + Name + ")");
			int nRet = 0;
			try 
			{
				nRet = (this._dataSet.Tables[0].Columns[Name].Ordinal);
			} 
			catch // (Exception ex) 
			{
				// throw new Exception("Ordinal [" + Name + "] not found.", ex);
			}

			return nRet;
		}

		/// <summary>
		/// Dispose of any held resources
		/// </summary>
		public void Dispose() {}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ken C. Len
Software Developer (Senior) LEN Associates Inc.
United States United States
Years of software consulting and software development using Microsoft development products such as Microsoft Content Management System, SQL Server Reporting Service, ASP.Net C# VB.Net, HTML and javascript web development, Visual Studio add-on development, C++ MFC/ATL and COM+ development, and ActiveX components.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 19 Oct 2005
Article Copyright 2005 by Ken C. Len
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid