# Session

The Session object holds the property values for a metered session. Objects of this type are created by CreateSession. InitProperty should be called for each property value before Close is called to send the properties to the server. SetProperty may be called to modify properties before the session is Closed, and GetProperty can be used to retrieve property values from the session.

## Program ID

MetraTechSDK.Session.1

## Session Methods

Close | After each property has been initialized to the correct value, Close sends the session and its parents and children, when appropriate, to the metering server.
CreateChildSession | Creates a child of this session. Any number of children can be created for a parent session. Once Close has been called on a session, no more children can be created.
GetProperty | Gets a property for the session.
InitProperty | Initializes a session's property.
SetProperty | Sets a previously initialized session property.
ToXML | Converts a session into its XML representation.

## Session Properties

Name | Obtains the Session's name.
ReferenceID | Obtains the Session's reference ID.
RequestResponse (get) | If synchronous metering has been enabled on this session, returns true.
RequestResponse (put) | Enables or disables the use of synchronous metering.
ResultSession | Obtains the session returned from the server when using synchronous metering. Set the RequestResponse flag to enable synchronous metering.
SessionID | Obtains the Session ID.

## Example

Example to be provided in a future release of this online help system.

# Method Detail

## Close

After each property has been initialized to the correct value, Close sends the session and its parents and children, when appropriate, to the metering server. The session is marked complete by a call to Close and further modification is not allowed on the session object. The metering server is allowed to begin processing a session after it has been closed. When a session is closed, any parents of the session are saved but will still be modifiable. Any children of the session will be closed and will not allow further modification.

### Visual Basic Syntax

Sub Close()

### C++ Syntax

HRESULT Close();

## CreateChildSession

Creates a child of this session. Any number of children can be created for a parent session. Once Close has been called on a session, no more children can be created. Sessions that have been saved can still have more children added to them. When the child is deleted, it is removed from the parent. When a parent session is deleted, it deletes any children still connected to it.

### Visual Basic Syntax

Function CreateChildSession(ServiceName As String) As Session

### C++ Syntax

HRESULT CreateChildSession([in] BSTR ServiceName, [out, retval] ISession** chldSess);

### Arguments

ServiceName

The service name of new child session.

### Return Value

New session object.

## GetProperty

Gets a property for the session.

### Visual Basic Syntax

Function GetProperty(Name As String, [Type As DataType = MTC_DT_CHAR])

### C++ Syntax

HRESULT GetProperty([in] BSTR name, [in, defaultvalue(1)] DataType Type, [out, retval] VARIANT * value);

### Arguments

Name

Property name.

Value

Property value.

## InitProperty

Initializes a session's property.

### Visual Basic Syntax

Sub InitProperty(Name As String, Value)

### C++ Syntax

HRESULT InitProperty([in] BSTR Name, [in] VARIANT Value);

### Arguments

Name

Property name.

Value

Property value.

## SetProperty

Sets a previously initialzed session property.

### Visual Basic Syntax

Sub SetProperty(Name As String, Value)

### C++ Syntax

HRESULT SetProperty([in] BSTR Name, [in] VARIANT Value);

### Arguments

Name

Property name.

Value

Property value.

## ToXML

This method will convert the session set into its XML representation.

### Visual Basic Syntax

Function ToXML as String

### C++ Syntax

HRESULT ToXML([out, retval] BSTR * xml);

### Return Value

MSIX/XML representation of the session set

# Property Detail

## Name

Obtains the Session's name.

This is a read-only property.

### Visual Basic Syntax

Property Name As String

### C++ Syntax

HRESULT Name([out, retval] BSTR *pVal);

### Return Value

The session's service name.

## ReferenceID

Obtains the Session's reference ID.

This is a read-only property.

### Visual Basic Syntax

Property ReferenceID As String

### C++ Syntax

HRESULT ReferenceID([out, retval] BSTR *pVal);

### Return Value

Session's reference ID: a shortened, printable version of the UID.

## RequestResponse (get)

If synchronous metering has been enabled on this session, returns true.

This is a read-only property.

### Visual Basic Syntax

Property RequestResponse As Boolean

### C++ Syntax

HRESULT RequestResponse([out, retval] VARIANT_BOOL *pVal);

### Return Value

True if synchronous metering is enabled.

## RequestResponse (put)

Enable or disable the use of synchronous metering.

This a writeable property.

Important: this flag must not be set to true for child sessions for compound metering. Only the parent can be set synchronous. The parent waits synchronously for the children to terminate.

### Visual Basic Syntax

Property RequestResponse As Boolean

### C++ Syntax

HRESULT RequestResponse([in] VARIANT_BOOL newVal);

### Arguments

newVal

True to enable synchronous metering.

## ResultSession

Obtains the session returned from the server when using synchronous metering. Set the RequestResponse flag to enable synchronous metering.

This is a read-only property.

### Visual Basic Syntax

Property ResultSession As Session

### C++ Syntax

HRESULT ResultSession([out, retval] ISession **pResultSession);

### Return Value

Response session from a synchronous metering event.

## SessionID

Obtains the Session Id.

### Visual Basic Syntax

Property SessionID As String

### C++ Syntax

HRESULT SessionID([out, retval] BSTR *pVal);

### Return Value

Session ID: base64 encoded Unique ID (UID).

# Enumerated Types Detail

## DataType

MTC_DT_WCHAR = 0
MTC_DT_CHAR = 1
MTC_DT_INT = 2
MTC_DT_FLOAT = 3
MTC_DT_DOUBLE = 4
MTC_DT_TIME = 5
MTC_DT_BOOL = 6
MTC_DT_DECIMAL = 7