Show TOC

Working with the GWM Generated Application Configuration FilesLocate this document in the navigation structure

Description and use of the generated application configuration files.

Prerequisites

Make sure that you have a GWM Outlook Add-In project to which you have added an SAP service reference.

Context

You can configure the generated application using configuration files.

There are two types of configuration files:
  • App.config file
  • <project>.adm file

Within these files is the information relevant for managing the application's runtime behavior.

You use the App.config file to configure local settings. These settings can then be used on a larger scale by using the <Project Name>.adm which enables the Global Group Policies.

To access these, open the Solution Explorer and then the SAP Service Reference folder in Visual Studio.

Note If configuration is maintained in both the <Project Name>.adm, and App.config files, the configuration maintained in the App.config file is given preference. If the <Project Name>.adm file is enabled via the Global Group Policies and configuration is not maintained in the App.config file for the login user, then configuration in the <Project Name>.adm is consumed.
Configure the following sections in the App.config file:
  • configSection
  • ServiceSection

    This section contains the keys for service details for each service selected while creating the project:

    • URL: The service URL option.
    • SSO: The project authentication mode. The values can be SAML20, X.509, Kerberos, or Basic.
    • Client: SAP Client to which the service is connected. For OData services from sources other than SAP Gateway, this option is empty.
    • RootCASubjectName: Root Certificate Subject Name.Required in order to specify X.509 Root certificate to be used with X.509 Certificate.
  • System.Diagnostics

    This section contains the configuration for the following listeners:

    • System.Diagnostics.TextWriterTraceListener

      This listener directs the tracing, or debugging output to a TextWriter, or to a stream.

    • System.Diagnostics.EventLogTraceListener

      Provides a simple listener that directs tracing, or debugging output to an EventLog, (EventViewer).

    • Switches

      Trace switches allow us to enable, disable, and filter tracing output.

Procedure

  1. Configure the System.Diagnostics.TextWriterTrace listener.

The table below shows the attributes of the configured trace listener:
Attribute Description
name The name of the trace listener. This can be any name.
type The type name of a class that derives from the TraceListener class
initializeData The name of the log file where entries are written.
traceOutputOptions A property used by trace listeners to determine which options or elements, should be included in the trace output.

Possible values are CallStack, DateTime, LogicalOperationStack, None, ProcessId, ThreadId, and Timestamp. The default is None.

Note

These lines above can be commented if you do not wish to add to a custom log file.

<add name="TraceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="Trace.log"  traceOutputOptions="DateTime"  />
</add>

  1. Configure the System.Diagnostics.EventLogTraceListener as follows:
    Note

    If you do not wish to add data to the custom log file, comment the lines below.

    <add name="EventListener"
                	type="System.Diagnostics.EventLogTraceListener"
                	initializeData="Application">
    </add>

The table below shows the attributes of the EventLogTraceListener configured.
Attribute Description
name The name of the trace listener. This can be any name.
type The type name of a class that derives from the TraceListener class
initializeData The name of the log file where entries are written.

  1. Configure the switch as follows:

<switches>
         <add name="TraceLevel" value="4"> 
The table below shows the values of theTraceLevel Enumeration switch.
Enumerated value Integer value Type of message displayed(written to specified output target)
Off 0 None (trace is disabled).
Error 1 Only error messages.
Warning 2 Warning messages and error messages.
Info 3 Informational, warning and error messages.
Verbose 4 Verbose, informational, warning and error messages

  1. Save the App.config file.

Updating the Application Configuration File

Procedure

Open the App.config file and update the following sections:
  1. ServiceSection: Update the service details such as URL, SSO, Client to enable X.509 authentication as follows:
    • URL: contact service URL that is configured for X.509 authentication
    • SSO: X.509
    • Client: SAP client to which the service enabled for X.509 authentication is connected.
    • RootCASubjectName: Root Certificate Subject Name is required in order to specify X.509 root certificate to be used with the X.509 Certificate.
  2. System.Diagnostics Section:
    1. Create a folder, for example, in the following path: C:\MyLogs\MyLogs.log
    2. Update the initializeData attribute of TraceListener to change the name of the log file.
    <add name="TraceListener" 
    		type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\MyLogs\MyLog.log"  traceOutputOptions="DateTime"  />
    	</add>
    
  3. Update the initializeData attribute of “EventListener” to change the source of EventViewer where the log entries are written.
    <add name="EventListener"
                type="System.Diagnostics.EventLogTraceListener"
                initializeData="MyNewSource">
    </add>
    

Extending the Application Configuration File

Procedure

  1. Open the application configuration file from the Start of the navigation path Solution Explorer Next navigation step SAP Service Reference  End of the navigation path folder.

Application configuration files contain settings specific to an application. This file contains configuration and settings that the application can read at runtime.

  1. Add a new configuration for country code, and provide a value of “DE” for example, as shown below:
    <appSettings>
    <app.key-'Country Code'value-'DE'/ >
    </appSettings>
    </configuration>

Updating the Generated Code to Read the Configuration

Context
The SAP.IW.Common DLL has the ConfigurationReaderHandler class, which exposes a method called GetConfigValue. This method can be used to read the configuration maintained in the App.config file at runtime.

In GWM Outlook application, all calls to the SAP system are made through the generated class ApplicationName>BusinessApplication.cs for example CRM_ContactsBusinessApplication.cs that was created for the contacts application.

Procedure
  1. In the Solution Explorer, expand Start of the navigation path Outlook Next navigation step Contact Next navigation step CRM_Contact  End of the navigation path.
  2. Double click on CRM_ContactsBusinessApplication.cs.
  3. Search for the GetAllData method.
    Note The name of the folder CRM_Contacts and CRM_ContactsBusinessApplication.cs may vary depending on the application name provided in the GWM wizard.
  4. Add the following code in GetAllData method to read the configuration value from the App.config file:
    string countryCode = ConfigurationReaderHandler.Instance.GetConfigValue("CountryCode");
    
    QueryOperationResponse<Outlook_CRM_Contacts.CONTACT.Contact> serviceresponse = null;
    // var serviceresponse = serviceContext.ContactCollection.Execute() as QueryOperationResponse<Outlook_CRM_Contacts.CONTACT.Contact>;
                    
    if (string.IsNullOrEmpty(countryCode))
    {
    serviceresponse = serviceContext.ContactCollection.Execute() as QueryOperationResponse<Outlook_CRM_Contacts.CONTACT.Contact>;
    }
    else
    {
    serviceresponse = serviceContext.ContactCollection.AddQueryOption("$filter", string.Format("CountryCode eq '{0}'", countryCode)).Execute() as QueryOperationResponse<Outlook_CRM_Contacts.CONTACT.Contact>;
     }