Click here to Skip to main content
15,885,216 members
Articles / Web Development / ASP.NET

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

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
19 Oct 2005CPOL8 min read 85.4K   406   26  
Demostrates how to render a report by passing XML to a data extension via SOAP calls.
using System;
using System.Xml;
using System.Diagnostics;
using System.Collections;

using Microsoft.ReportingServices.DataProcessing;

namespace CustomDataExtension
{
	/// <summary>
	/// </summary>
	public class DataSetCommand : IDbCommand 
	{
		private string _commandText;
		private DataSetParameterCollection _parameters = new DataSetParameterCollection();

		/// <summary>
		/// Default Constructor
		/// </summary>
		public DataSetCommand() {}

		/// <summary>
		/// Attempts to cancel the current command
		/// </summary>
		public void Cancel () 
		{
			throw (new NotSupportedException ("Command cancellation is not currently supported"));
		}

		/// <summary>
		/// Gets/sets the current command type
		/// </summary>
		/// <remarks>
		/// Only the Text command type is supported for this extension
		/// </remarks>
		public CommandType CommandType 
		{
			get { return (CommandType.Text); }
			set 
			{
				if (value != CommandType.Text)
					throw (new NotSupportedException ("Only the Text command type is supported for this extension"));
			}
		}

		/// <summary>
		/// Retrieves an interface used to retrieve data and schema information
		/// </summary>
		/// <param name="behavior">The requested behavior</param>
		/// <returns>An interface to a data reader object</returns>
		public IDataReader ExecuteReader(CommandBehavior behavior) 
		{
			XmlDocument doc = new XmlDocument();
			try
			{
				// load the CommandText XML and append dataset parameters
				doc.LoadXml(CommandText);

				// Append all the dataset parameter
				// example: WebMethod contains which web service method to execute.				
				DataSetParameter parameter = null;
				IEnumerator enumerator = _parameters.GetEnumerator();
				while (enumerator.MoveNext())
				{
					parameter = (DataSetParameter) enumerator.Current;
					XmlElement elem = doc.CreateElement(parameter.ParameterName);
					elem.AppendChild(doc.CreateTextNode(parameter.Value.ToString()));
					doc.DocumentElement.AppendChild(elem);
				}
			}
			catch (Exception ex)
			{
				throw new Exception("Invalid Xml command Text: " + CommandText, ex);
			}

			return new DataSetDataReader(doc.InnerXml);
		}

		/// <summary>
		/// Gets/sets the command timeout.
		/// </summary>
		/// <remarks>
		/// A CommandTimeout other than 0 is not supported by this extension.
		/// </remarks>
		public Int32 CommandTimeout 
		{
			get {return (0);}
			set {} //Do nothing
		}

		/// <summary>
		/// Gets/sets the current command text
		/// </summary>
		/// <remarks>
		/// This CommandText will be an XML string containing filter information etc.
		/// </remarks>
			public String CommandText 
			{
				get { return (this._commandText); }
				set { this._commandText = value; }
			}

		/// <summary>
		/// Gets/sets an object that allows action on the transaction
		/// </summary>
		/// <returns>null since we do not support transactions</returns>
		public IDbTransaction Transaction 
		{
			get { return null; }
			set { throw (new NotSupportedException());	}
		}


		IDataParameterCollection IDbCommand.Parameters
		{
			get  { return _parameters; }
		}


		/// <summary>
		/// Creates a new data parameter (not used)
		/// </summary>
		public IDataParameter CreateParameter() 
		{
			return (IDataParameter)(new DataSetParameter()) ;
		}

		/// <summary>
		/// Retreives the current parameters list (not used)
		/// </summary>
		public IDataParameterCollection Parameters 
		{
			get { return _parameters; }
		}

		/// <summary>
		/// Dispose of any held resources
		/// </summary>
		public void Dispose() 
		{
			if (_parameters != null)
			{
				_parameters.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)


Written By
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.

Comments and Discussions