Host BI Silverlight component in ASP.NET MVC Web Project
2 Jun 202113 minutes to read
The following steps explain how to add the Silverlight components in MVC project:
- Open Visual Studio IDE.
-
Go to FileNewProject and create a new Silverlight application.
A dialog window opens as shown below:
-
Select Silverlight Application from the New Project dialog window and click OK.
The New Silverlight Application dialog opens as shown in the following screenshot:
The Solution Explorer window shows the Silverlight application with MVC project.
-
Double-click to open the Main.xaml which is found under the Silverlight project in Solution Explorer as shown below:
- Drag and drop the OlapGrid from the toolbox to the MainPage.xaml.
- Add the following two assemblies as references to the web project:
- Syncfusion.Olap.Base
- Syncfusion.OlapSilverlight.BaseWrapper
- Add a WCF Service to the web project by right-clicking the Project Add New Item WCF Service.
-
Name the service as OlapManager and delete the IOlapManager.cs file as the service has to be inherited with the IOlapDataProvider.
- Inherit the newly added WCF service with the IOlapDataProvider and explicitly implement the IOlapDataProvider.
-
The connection to the database is done with the help of the WCF service. The service has to be created and instantiated as described in the below code snippet.
The WCF Service has to implement the IOlapDataProvider interface. To implement this interface, you require the OlapDataProvider, which can be instantiated by passing the connection string.
The interface can be implemented as shown in the following code snippet:
public class OlapManager : IOlapDataProvider { Syncfusion.OlapSilverlight.Manager.OlapDataProvider dataManager; /// <summary> /// Initializes a new instance of the <see cref="OlapManager"/> class. /// </summary> public OlapManager() { string connectionString = "DataSource=localhost;Initial Catalog=Adventure Works DW"; // Instantiating the OlapDataProvider with connection string. dataManager = new OlapDataProvider(connectionString); } #region IOlapDataProvider Members /// <summary> /// Executing the CellSet by passing OlapReport. /// </summary> /// <param name="report">The report.</param> /// <returns> The CellSet </returns> public Syncfusion.OlapSilverlight.Data.CellSet ExecuteOlapReport(Syncfusion.OlapSilverlight.Reports.OlapReport report) { Syncfusion.OlapSilverlight.Data.CellSet cellSet = this.dataManager.ExecuteOlapReport(report); // Closing the provider connection. this.dataManager.DataProvider.CloseConnection(); return cellSet; } /// <summary> /// Executing the CellSet by passing MDX Query. /// </summary> /// <param name="mdxQuery">The MDX query.</param> /// <returns> The CellSet </returns> public Syncfusion.OlapSilverlight.Data.CellSet ExecuteMdxQuery(string mdxQuery) { Syncfusion.OlapSilverlight.Data.CellSet cellSet = this.dataManager.ExecuteMdxQuery(mdxQuery); // Closing the provider connection. this.dataManager.DataProvider.CloseConnection(); return cellSet; } public MemberCollection GetChildMembers(string memberUniqueName, string cubeName) { throw new NotImplementedException(); } public CubeSchema GetCubeSchema(string cubeName) { throw new NotImplementedException(); } public CubeInfoCollection GetCubes() { throw new NotImplementedException(); } public MemberCollection GetLevelMembers(string levelUniqueName, string cubeName) { throw new NotImplementedException(); } #endregion }
Public Class OlapManager Implements IOlapDataProvider Private dataManager As Syncfusion.OlapSilverlight.Manager.OlapDataProvider ''' <summary> ''' Initializes a new instance of the <see cref="OlapManager"/> class. ''' </summary> Public Sub New() Dim connectionString As String = "DataSource=localhost;Initial Catalog=Adventure Works DW" ' Instantiating the OlapDataProvider with connection string dataManager = New OlapDataProvider(connectionString) End Sub #Region "IOlapDataProvider Members" ''' <summary> ''' Executing the CellSet by passing OlapReport ''' </summary> ''' <param name="report">The report.</param> ''' <returns></returns> Public Function ExecuteOlapReport(ByVal report As Syncfusion.OlapSilverlight.Reports.OlapReport) As Syncfusion.OlapSilverlight.Data.CellSet Dim cellSet As Syncfusion.OlapSilverlight.Data.CellSet = Me.dataManager.ExecuteOlapReport(report) ' Closing the provider connection Me.dataManager.DataProvider.CloseConnection() Return cellSet End Function ''' <summary> ''' Executing the CellSet by passing MDX Query ''' </summary> ''' <param name="mdxQuery">The MDX query.</param> ''' <returns> The CellSet </returns> Public Function ExecuteMdxQuery(ByVal mdxQuery As String) As Syncfusion.OlapSilverlight.Data.CellSet Dim cellSet As Syncfusion.OlapSilverlight.Data.CellSet = Me.dataManager.ExecuteMdxQuery(mdxQuery) 'Closing the provider connection. Me.dataManager.DataProvider.CloseConnection() Return cellSet End Function Public Function GetChildMembers(ByVal memberUniqueName As String, ByVal cubeName As String) As MemberCollection Throw New NotImplementedException() End Function Public Function GetCubeSchema(ByVal cubeName As String) As CubeSchema Throw New NotImplementedException() End Function Public Function GetCubes() As CubeInfoCollection Throw New NotImplementedException() End Function Public Function GetLevelMembers(ByVal levelUniqueName As String, ByVal cubeName As String) As MemberCollection Throw New NotImplementedException() End Function #End Region End Class
-
Include the custom binding and the service endpoint address in the Web.Config file under the ServiceModel section.
<!--Binding--> <bindings> <customBinding> <binding name="binaryHttpBinding"> <binaryMessageEncoding/> <httpTransport maxReceivedMessageSize="2147483647"/> </binding> </customBinding> </bindings> <!—Endpoint Address--> <services> <service name="SilverlightApplication1.Web.OlapManager" > <endpoint address="binary" binding="customBinding" bindingConfiguration="binaryHttpBinding" contract="Syncfusion.OlapSilverlight.Manager.IOlapDataProvider"> </endpoint> </service> </services>
- Add the System.ServiceModel assembly as a reference for the Silverlight project.
- Add the following namespace in MainPage.xaml.cs:
- System.ServiceModel
- System.ServiceModel.Channels
- Syncfusion.OlapSilverlight.Reports
- Syncfusion.Silverlight.Grid
- Syncfusion.OlapSilverlight.Manager
- Syncfusion.OlapSilverlight.Engine
- Instantiate the service from MainPage.xaml.cs which is in the Silverlight Project.
-
Declare the IOlapDataProvider for service instantiation.
// Declaring the IOlapDataProvider for service instantiation. IOlapDataProvider DataProvider = null;
'Declaring the IOlapDataProvider for service instantiation. Dim DataProvider As IOlapDataProvider = Nothing
-
Specify the custom binding and instantiate the DataProvider from the ChannelFactory.
private void InitializeConnection() { System.ServiceModel.Channels.Binding customBinding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement { MaxReceivedMessageSize = 2147483647 }); EndpointAddress address = new EndpointAddress(new Uri(App.Current.Host.Source + "../../../../OlapManager.svc/binary")); ChannelFactory<IOlapDataProvider> clientChannel = new ChannelFactory<IOlapDataProvider>(customBinding, address); DataProvider = clientChannel.CreateChannel(); }
Private Sub InitializeConnection() Dim customBinding As System.ServiceModel.Channels.Binding = New CustomBinding(New BinaryMessageEncodingBindingElement(), New HttpTransportBindingElement With {.MaxReceivedMessageSize = 2147483647}) Dim address As EndpointAddress = New EndpointAddress(New Uri(App.Current.Host.Source & "../../../../OlapManager.svc/binary")) Dim clientChannel As ChannelFactory(Of IOlapDataProvider) = New ChannelFactory(Of IOlapDataProvider)(customBinding, address) DataProvider = clientChannel.CreateChannel() End Sub
-
Create the Report.
For creating reports there is a report object called OlapReport. The OlapReport object contains CategoricalItems, SeriesItems, SlicerItems, and FilterItems.
The OlapReport is associated with the OlapDataManager as the current report property. When a report is set to the current report, an event triggers and the control renders based on the current report that is set.
-
Bind the data to OlapGridData.
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // Initialize the service connection. this.InitializeConnection(); // Instantiating the OlapDataManager. OlapDataManager m_OlapDataManager =new OlapDataManager(); // Specifying the DataProvider for OlapDataManager. m_OlapDataManager.DataProvider = this.DataProvider; // Set current report for OlapDataManager. m_OlapDataManager.SetCurrentReport(CreateOlapReport()); // Specifying the OlapDataManager for OlapGrid. this.olapGrid1.OlapDataManager = m_OlapDataManager; // Data Binding. this.olapGrid1.DataBind(); }
Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) 'Initialize the service connection. Me.InitializeConnection() 'Instantiating the OlapDataManager. Dim m_OlapDataManager As OlapDataManager = New OlapDataManager() 'Specifying the DataProvider for OlapDataManager. m_OlapDataManager.DataProvider = Me.DataProvider 'Set current report for OlapDataManager. m_OlapDataManager.SetCurrentReport(CreateOlapReport()) ' Specifying the OlapDataManager for OlapGrid. Me.olapGrid1.OlapDataManager = m_OlapDataManager ' Data Binding. Me.olapGrid1.DataBind() End Sub