Skip to Content

Single Signon using C#

Hi, Have anyone been able to make and use a single sign-on connection using C#?

I successfully make the connection til the client and just after that I make the single-signon (As the UI-reference exsampel does). This single-signon is succesfully, but when I use the SAPBobs-company which I connected, in an event the company-object is corrupted (A Simple debugging fails for some reason)...

Anyone been able to use this feature with C#

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Jun 04, 2004 at 08:24 AM

    This exsampel show the problems (see the comments in code on the event-handler method)

    public SAPbobsCOM.Company c = new SAPbobsCOM.Company();

    public SAPbouiCOM.Application app;

    public SAPbouiCOM.SboGuiApi gui = new SAPbouiCOM.SboGuiApiClass();

    private void Form1_Load(object sender, System.EventArgs e) {

    //Connect til SAP

    try {

    //Henter connection-string fra commandolinie og laver connect til SBO (gui)

    gui.Connect(Environment.GetCommandLineArgs()[1]);

    try {

    //Vælger SBO (Hvis flere kørende)

    app = gui.GetApplication(-1);

    }

    catch(Exception exp) {

    throw new Exception("Fejl under oprettelse af Application: "+exp.Message);

    }

    }

    catch {

    throw new Exception("SBO er ikke startet. Start det og prøv igen");

    }

    string cookie = c.GetContextCookie();

    string conStr = app.Company.GetConnectionContext(cookie);

    if(c.Connected) {

    c.Disconnect();

    }

    if(c.SetSboLoginContext(conStr) == 0) {

    c.Connect();

    }

    //Call methos that use company

    normal_method();

    //Registration Eventhandlers

    app.MenuEvent+=new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler(app_MenuEvent);

    }

    private void app_MenuEvent(ref SAPbouiCOM.MenuEvent pVal, out bool BubbleEvent) {

    BubbleEvent = false;

    //At this point c is corrupted (In a watch all properties is "error: cannot obtain value string")

    if(c.Connected) {

    MessageBox.Show("Test");

    }

    //Also if i try this alle properties in c2's watch is "<error: an exception of type: {System.InvalidCastException} occurred> SAPbobsCOM.BoSuppLangs"

    SAPbobsCOM.Company c2 = new SAPbobsCOM.Company();

    }

    private void normal_method() {

    if(c.Connected) {

    MessageBox.Show("Test2");

    }

    }

    Add comment
    10|10000 characters needed characters exceeded