Click to Rate and Give Feedback
Reporting Services - Reporting Services Programming
Identifying Session State

Identifying Session State

Hypertext Transfer Protocol (HTTP) is a connectionless and stateless protocol, which means that it does not automatically indicate whether different requests come from the same client or even whether a single browser instance is still actively viewing a page or site. Sessions create a logical connection to maintain state between server and client over HTTP. The user-specific information relevant to a particular session is known as the session state.

Session management is correlating an HTTP request with other previous requests generated from the same session. Without session management, these requests appear unrelated to the Web service because of the connectionless and stateless nature of the HTTP protocol.

Reporting Services provides an infrastructure for managing session state. While they are communicating to a report server, clients use session state to manage report viewing and user navigation to other pages in a report, and to show or hide sections of a report. A unique session exists for each client application running on a client computer.

In general, the lifetime of a session starts when a user navigates to a browser or client application and selects a report to view within it. The session ends when the user closes the application, even if the user navigates to and views additional reports before closing the application.

From a Web service perspective, the lifetime starts when the Web service method Render is called. The session ends when all of the reports associated with the session have timed out. Applications can use the same session when making multiple requests to the Web service methods Render and RenderStream.

While a report is in session, the underlying report stored in the report server database can change. For example, the report definition can change, the report can be deleted or moved, and user permissions can change. If the report is in an active session, it is not affected by changes made to the underlying report (that is, the report stored in the report server database).

You can also manage a report session using URL access commands. For more information, see Managing Report Sessions on a URL.

In the following code example, each active session is identified and tracked using the SessionID property of the SOAP header SessionHeader. The SessionID property contains only valid ASCII characters that are permitted on URLs.

The following example shows the use of the SessionId property for tracking and identifying active sessions:

Sub Main()
    Dim rs As New ReportingService()
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials
    
    Try
        Dim result As Byte() = Nothing
        Dim reportPath As String = "/Samples/Employee Sales Summary"
        Dim format As String = "HTML4.0"
        Dim historyID As String = Nothing
        Dim startPage As Integer = 1
        
        ' Set the device info settings for the rendering format.
        Dim deviceInfo As String = String.Format(" _
        <DeviceInfo><Toolbar>{0}</Toolbar><StartPage>{1}</StartPage></DeviceInfo>", "False", startPage)
        
        ' Prepare report parameter.
        Dim parameters(2) As ParameterValue
        parameters(0) = New ParameterValue()
        parameters(0).Name = "EmpID"
        parameters(0).Value = "38"
        parameters(1) = New ParameterValue()
        parameters(1).Name = "ReportMonth"
        parameters(1).Value = "6" ' June
        parameters(2) = New ParameterValue()
        parameters(2).Name = "ReportYear"
        parameters(2).Value = "2004"
        
        Dim credentials As DataSourceCredentials() = Nothing
        Dim showHideToggle As String = Nothing
        Dim encoding As String
        Dim mimeType As String
        Dim warnings As Warning() = Nothing
        Dim reportHistoryParameters As ParameterValue() = Nothing
        Dim streamIDs As String() = Nothing
        
        rs.SessionHeaderValue = New SessionHeader()
        
        ' Make the first call to Render.
        Console.WriteLine("Call to Render.")
        
        result = rs.Render(reportPath, format, historyID, deviceInfo, parameters, 
           credentials, showHideToggle, encoding, mimeType, reportHistoryParameters, warnings, streamIDs)
        
        Console.WriteLine("SessionID after call to Render: {0}", rs.SessionHeaderValue.SessionId)
        Console.WriteLine(("Execution date and time: " + rs.SessionHeaderValue.ExecutionDateTime))
        Console.WriteLine(("Is new execution: " + rs.SessionHeaderValue.IsNewExecution))
        
        ' Change device info start page to page two.
        startPage = 2
        
        ' Set the device info settings for the rendering format.
        deviceInfo = String.Format("<DeviceInfo><Toolbar>{0}</Toolbar><StartPage>{1}</StartPage></DeviceInfo>",
            "False", startPage)
        
        ' Make the second call to Render.
        Console.WriteLine("Second call to Render.")
        
        result = rs.Render(reportPath, format, historyID, deviceInfo, parameters, 
           credentials, showHideToggle, encoding, mimeType, reportHistoryParameters, warnings, streamIDs)
        
        Console.WriteLine("SessionID after call to Render: {0}", rs.SessionHeaderValue.SessionId)
        Console.WriteLine(("Execution date and time: " + rs.SessionHeaderValue.ExecutionDateTime))
        Console.WriteLine(("Is new execution: " + rs.SessionHeaderValue.IsNewExecution))
    
    Catch e As Exception
        Console.WriteLine((e.Message + ": " + e.StackTrace))
    End Try
End Sub 'Main
static void Main()
{
   ReportingService rs = new ReportingService();
   rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

   try
   {
      byte[] result = null;
      string reportPath = "/Samples/Employee Sales Summary";
      string format = "HTML4.0";
      string historyID = null;
      int startPage = 1;

      // Set the device info settings for the rendering format.
      string deviceInfo = String.Format(
          @"<DeviceInfo><Toolbar>{0}</Toolbar><StartPage>{1}</StartPage></DeviceInfo>", "False", startPage);

      // Prepare report parameter.
      ParameterValue[] parameters = new ParameterValue[3];
      parameters[0] = new ParameterValue();
      parameters[0].Name = "EmpID";
      parameters[0].Value = "38";
      parameters[1] = new ParameterValue();
      parameters[1].Name = "ReportMonth";
      parameters[1].Value = "6"; // June
      parameters[2] = new ParameterValue();
      parameters[2].Name = "ReportYear";
      parameters[2].Value = "2004";

      DataSourceCredentials[] credentials = null;
      string showHideToggle = null;
      string encoding;
      string mimeType;
      Warning[] warnings = null;
      ParameterValue[] reportHistoryParameters = null;
      string[] streamIDs = null;

      rs.SessionHeaderValue = new SessionHeader();

      // Make the first call to Render.
      Console.WriteLine("Call to Render.");

      result = rs.Render(reportPath, format, historyID, deviceInfo, parameters,
         credentials, showHideToggle, out encoding, out mimeType,
         out reportHistoryParameters, out warnings, out streamIDs);

      Console.WriteLine("SessionID after call to Render: {0}", rs.SessionHeaderValue.SessionId);
      Console.WriteLine("Execution date and time: " + rs.SessionHeaderValue.ExecutionDateTime);
      Console.WriteLine("Is new execution: " + rs.SessionHeaderValue.IsNewExecution);

      // Change device info start page to page two.
      startPage = 2;

      // Set the device info settings for the rendering format.
      deviceInfo = String.Format(@"<DeviceInfo><Toolbar>{0}</Toolbar><StartPage>{1}</StartPage></DeviceInfo>", "False", startPage);

      // Make the second call to Render.
      Console.WriteLine("Second call to Render.");

      result = rs.Render(reportPath, format, historyID, deviceInfo, parameters, 
         credentials, showHideToggle, out encoding, out mimeType,
         out reportHistoryParameters, out warnings, out streamIDs);

      Console.WriteLine("SessionID after call to Render: {0}", rs.SessionHeaderValue.SessionId );
      Console.WriteLine("Execution date and time: " + rs.SessionHeaderValue.ExecutionDateTime);
      Console.WriteLine("Is new execution: " + rs.SessionHeaderValue.IsNewExecution);

   }

   catch (Exception e)
   {
      Console.WriteLine(e.Message + ": " + e.StackTrace);
   }
}

The following output is similar to what you might see as a result of running the preceding code example. The SessionId property for both calls to the Render method contain the same value. The report itself does not run again when Render is called a second time:

Call to Render.
SessionID after call to Render: eno4juntb0biaa551x1lu43k
Execution date and time: 2003-02-10T10:38:15
Is new execution: True
Second call to Render.
SessionID after call to Render: eno4juntb0biaa551x1lu43k
Execution date and time: 2003-02-10T10:38:15
Is new execution: False
See Also

Render Method

RenderStream Method

Reporting Services Web Service Library

SessionId Property

Using Reporting Services SOAP Headers

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker