Share via


Binding to a Managed RAS server Using ReportAppFactory.OpenDocument() Method

Note

This page describes functionality that is not available in Crystal Reports for Visual Studio, but is available in one of the upgraded versions. For more information about Crystal Reports for Visual Studio, see What is Crystal Reports for Visual Studio? For more information about upgraded versions, see Upgrade Options.

Object Model

This report binding scenario uses ReportClientDocument (see Report Binding with ReportClientDocument Object Model (RAS)).

Location of Reports

Stored on a server in Crystal Reports Server or BusinessObjects Enterprise.

Description

This report binding scenario accesses the ReportClientDocument object model directly. It retrieves an EnterpriseSession, a ReportAppFactory, and an InfoObject. It then passes the ID property of InfoObject and the integer 0 (optional parameter in Visual Basic) to the OpenDocument() method of ReportAppFactory, which returns an instance of ReportClientDocument from Crystal Reports Server or BusinessObjects Enterprise. For a code sample, see the Implementation section below.

Pros

  • Viable method for interacting with reports in the ReportClientDocument object model using RAS within CE 9 and up.

  • Significant performance gains due to superior performance of the report engine in the managed RAS server within Crystal Reports Server or BusinessObjects Enterprise. See Comparing Architectures Across Business Objects Reporting Solutions for more information.

  • Maintains all original code that interacted with reports using the ReportDocument object model, while still providing full access to the underlying ReportClientDocument object model through the ReportDocument.ReportClientDocument property.

    Note

    The ReportClientDocument object model allows you to programmatically create, modify and save changes to the report definition file. For further information, see ReportClientDocument Object Model (RAS) in Architecture.

  • Direct access to the ReportClientDocument object model.

Cons

To load a report from Crystal Reports Server or BusinessObjects Enterprise into the RAS server using the OpenDocument method of ReportAppFactory

  • Crystal Reports Server or BusinessObjects Enterprise must be installed and verified to be working.

  • Crystal Reports Server or BusinessObjects Enterprise SDK (including the .NET assemblies) must be installed on your development machine.

    Note

    If you have installed Crystal Reports Server or BusinessObjects Enterprise on your development machine, the SDK is included with that installation.

  • Locate and write down the name of a Crystal Reports Server or BusinessObjects Enterprise server. For purposes of this example, the server name is "BOE01".

This procedure works only with a project that has been created from Project Setup. Project Setup contains specific namespace references and code configuration that is required for this procedure, and you will be unable to complete the procedure without that configuration. Therefore, before you begin this procedure, you must first follow the steps in Project Setup.

  1. Use the Publishing Wizard to publish the Chart.rpt to the Crystal Reports Server or BusinessObjects Enterprise server.
> [!NOTE]
> <P>To learn how to use the Publishing Wizard, see the Crystal Reports Server or BusinessObjects Enterprise User documentation.</P>


For information about sample reports, see [Sample Reports' Directory](ms225622\(v=vs.90\).md).
  1. Add the following assembly references to your project:
1.  CrystalDecisions.Enterprise.Framework
2.  CrystalDecisions.Enterprise.InfoStore
3.  CrystalDecisions.ReportAppServer.ClientDoc
  1. At the top of the code-behind page, add a "Imports" [Visual Basic] or "using" [C#] statement for the CrystalDecisions.Enterprise namespace and the CrystalDecisions.ReportAppServer.ClientDoc namespace.
``` vb
Imports CrystalDecisions.Enterprise
Imports CrystalDecisions.ReportAppServer.ClientDoc
```

``` csharp
using CrystalDecisions.Enterprise;
using CrystalDecisions.ReportAppServer.ClientDoc;
```

You are now ready to add code that opens the report in the RAS server within Crystal Reports Server or BusinessObjects Enterprise.
  1. Within the ConfigureCrystalReports() method (that you have created in Project Setup), declare a serverName string and set it to the name of the Crystal Reports Server or BusinessObjects Enterprise server.
``` vb
Dim serverName As String = "BOE01"
```

``` csharp
string serverName = "BOE01";
```
  1. Declare and instantiate the SessionMgr class.
``` vb
Dim mySessionMgr As SessionMgr = New SessionMgr()
```

``` csharp
SessionMgr sessionMgr = new SessionMgr();
```
  1. Pass the user name (Administrator), the password (blank), the serverName variable, and the logon type (secEnterprise) to the Logon method of the SessionMgr instance and retrieve it as an instance of EnterpriseSession.
``` vb
Dim myEnterpriseSession As EnterpriseSession = mySessionMgr.Logon(
_
        "Administrator", "", serverName, "secEnterprise")
```

``` csharp
EnterpriseSession enterpriseSession = sessionMgr.Logon(
      "Administrator", "", serverName, "secEnterprise");
```
  1. Retrieve the InfoStore service (as EnterpriseService) from the GetService method of EnterpriseSession.
``` vb
Dim myEnterpriseService As EnterpriseService = _
        myEnterpriseSession.GetService("InfoStore")
```

``` csharp
EnterpriseService enterpriseService =
enterpriseSession.GetService("InfoStore");
```
  1. Declare and instantiate InfoStore using the retrieved InfoStore service.
``` vb
Dim myInfoStore As InfoStore = New InfoStore(myEnterpriseService)
```

``` csharp
InfoStore infoStore = new InfoStore(enterpriseService);
```
  1. Re-assign the value of the EnterpriseService instance, by passing the "RASReportFactory" string to the GetService() method of EnterpriseSession.
``` vb
myEnterpriseService =
myEnterpriseSession.GetService("RASReportFactory")
```

``` csharp
enterpriseService =
enterpriseSession.GetService("RASReportFactory");
```
  1. Return the Interface property of the EnterpriseService as an object variable.
``` vb
Dim rrfObject As Object = myEnterpriseService.Interface
```

``` csharp
Object rrfObject = enterpriseService.Interface;
```
  1. Cast the object variable to a ReportAppFactory instance.
``` vb
Dim myReportAppFactory As ReportAppFactory = CType(rrfObject,
ReportAppFactory)
```

``` csharp
ReportAppFactory reportAppFactory = (ReportAppFactory)rrfObject;
```
  1. Enter the query string below to query Crystal Reports Server or BusinessObjects Enterprise for the report.
``` vb
Dim queryString As String = "Select SI_ID, SI_NAME, SI_PARENTID
From CI_INFOOBJECTS " _
                & "Where SI_PROGID='CrystalEnterprise.Report' "
_
                & "And SI_NAME Like 'Chart'"
```

``` csharp
string queryString = "Select SI_ID, SI_NAME, SI_PARENTID From
CI_INFOOBJECTS "
   + "Where SI_PROGID='CrystalEnterprise.Report' "
   + "And SI_NAME Like 'Chart'";
```
  1. Retrieve an InfoObjects indexed class containing the query result by passing the query string to the Query method of InfoStore.
``` vb
Dim myInfoObjects As InfoObjects = myInfoStore.Query(queryString)
```

``` csharp
InfoObjects infoObjects = infoStore.Query(queryString);
```
  1. Retrieve the InfoObject from the first column of the InfoObjects indexed class.
> [!NOTE]
> <P>The InfoObjects indexed class is 1-based, not 0-based.</P>


``` vb
Dim myInfoObject As InfoObject = myInfoObjects(1)
```

``` csharp
InfoObject infoObject = infoObjects[1];
```
  1. Declare and instantiate ReportClientDocument.
``` vb
Dim myReportClientDocument As ReportClientDocument = New
ReportClientDocumentClass()
```

``` csharp
ReportClientDocument reportClientDocument = new
ReportClientDocumentClass();
```
  1. Pass the ID property of InfoObject and the integer 0 (this is optional in Visual Basic) to the OpenDocument method of the ReportAppFactory instance.
> [!NOTE]
> <P>This opens the report from the Report Application Server (RAS) in Crystal Reports Server or BusinessObjects Enterprise as a ReportClientDocument instance.</P>


``` vb
myReportClientDocument =
myReportAppFactory.OpenDocument(myInfoObject.ID, 0)
```

``` csharp
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID,
0);
```
  1. Bind the ReportClientDocument instance to the CrystalReportViewer control.
``` vb
myCrystalReportViewer.ReportSource = myReportClientDocument
```

``` csharp
crystalReportViewer.ReportSource = reportClientDocument;
```
  1. To view the report, build and run your project.

See Also