Sunday, December 4, 2022

[Part 1-3] Single Sign on Connection

Properties current SAP Connection command line argument: 0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056 


using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using System.Windows.Forms;

using SAPbobsCOM;


namespace MySAPB1WinFormApp

{


  



    static class Program

    {

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        /// 


        public static SAPbouiCOM.Application oApplication = null;

        public static SAPbobsCOM.Company oCompany = null;

        [STAThread]

        static void Main()

        {

            if(IsSAPConnected()==true)

            {


            }

        }



        public static bool IsSAPConnected()

        {

            try

            {

                int oErrorValue = -1;

                string oErrorMessage = string.Empty;



                //***Step:1

                //***** in this step we getting the Application 

                SAPbouiCOM.SboGuiApi oSboGuiApi = new SAPbouiCOM.SboGuiApi();

                string[] strCon = Environment.GetCommandLineArgs();

                oSboGuiApi.Connect(strCon[1]);

                oApplication = oSboGuiApi.GetApplication(-1);

                //**************************************************



                oApplication.StatusBar.SetText("SampleFormAddon is Connection", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);



                //*** Step 2

                // in this step company object generates the cookie for the current session  with the help of  method  GetContextcookie()


                oCompany = new SAPbobsCOM.Company();

                string oCookies =(string) oCompany.GetContextCookie();


                //**********************************************************


                //*** Step 3

                //****** in this step  GetConnectionContext(oCookies) method of the application object encrypt the connection string with the help of Cookies provided by the DI API


                string constr = oApplication.Company.GetConnectionContext(oCookies);


                //*************************************


                if (oCompany.Connected == true)

                    oCompany.Disconnect();


                //***Step4

                //*** in this step  setsbologincontext(constr) method of company object deciphers the encrypted  connection information and sets the connection parameter to the company object


                oCompany.SetSboLoginContext(constr);

                //**************************************************



                ///**Step 5

                ///*** in this step with the help of connect() method we establish connection with the company


                oErrorValue = oCompany.Connect();


                if (oErrorValue == 0)

                {

                    oApplication.MessageBox("Single Sign on  connection established", 1, "Alert", "", "");

                    return true;

                }


                else

                    oCompany.GetLastError(out oErrorValue, out oErrorMessage);

                    oApplication.MessageBox("ErrorCode" + oErrorValue + "ErroMessage" + oErrorMessage.ToString(), 1, "Error", "", "");

                    return false;


            }

            catch (Exception ex)

            {


                throw new Exception(ex.ToString());

            }

        }

    }

}

No comments:

Post a Comment

2315907 - Starting HANA automatically after Host has been started

  Symptom By default the SAP HANA database is configured so that it is not started automatically when the SAP HANA host is rebooted. Environ...