Skip to Content
Technical Articles
Author's profile photo Maria Trinidad MARTINEZ GEA

SAP Business One Service Layer – SSO with UI API

As of SAP Business One 9.2, version for SAP HANA, besides the normal login, Service Layer supports SSO with SAP Business One SDK UI API.

Important Note:
Domain user SSO with Service Layer:

  • supported only for On-Demand Environment.

B1 user SSO with Service Layer:

  • supported only for On-Premise Environment.

In order to use Service Layer SSO you just have to connect as usual to the UI API and use the UI API SBO_Application object to get the Service Layer B1SESSION and ROUTEID cookies.

 

Here you have a very simple sample getting Service Layer context from UI API:

string serviceLayerAddress = "https://hanaserver:50000/b1s/v1";
string sConnectionContext = SBO_Application.Company.GetServiceLayerConnectionContext(serviceLayerAddress);

 

And a method getting Service Layer context and using it to call Service Layer via HttpWebRequest class:

private int PlayServiceLayer()
{
  string serviceLayerAddress = "https://hanaserver:50000/b1s/v1";
  string sConnectionContext = null;
  //Step 1: Get a session cookie from service layer
  try {
      sConnectionContext = SBO_Application.Company.GetServiceLayerConnectionContext(serviceLayerAddress);
  }
  catch (System.Exception ex)
  {
    continue;
  }
    
  if (sConnectionContext == null)
  {
    SBO_Application.MessageBox("Get service layer connection context error", 1, "Err", "", "");
    return -1;
  }
  //Step 2: Send requests with session cookie
  try {
    var request = WebRequest.Create(serviceLayerAddress + "/Items?$top=1") as HttpWebRequest;
    request.AllowAutoRedirect = false;
    request.Timeout = 30 * 1000;
    request.ServicePoint.Expect100Continue = false;
    request.CookieContainer = new CookieContainer();
    ServicePointManager.ServerCertificateValidationCallback += BypassSslCallback;
    string[] cookieItems = sConnectionContext.Split(';');
    foreach (var cookieItem in cookieItems) {
      string[] parts = cookieItem.Split('=');
      if (parts.Length == 2) {
        request.CookieContainer.Add(request.RequestUri, new Cookie(parts[0].Trim(), parts[1].Trim()));
      }
    }
    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
    if (response.StatusCode != HttpStatusCode.OK) {
      SBO_Application.MessageBox("Get item error", 1, "Err", "", "");
      return -1;
    }
    string responseContent = null;
    using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) {
      responseContent = reader.ReadToEnd();
    }
    SBO_Application.MessageBox(responseContent, 1, "Ok", "", "");
  }
  catch (System.Exception ex) {
    SBO_Application.MessageBox(ex.ToString(), 1, "Err", "", "");
  }
  return 0;
}

Hope it helps
Trinidad.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Daniel Teixeira
      Daniel Teixeira

      Service Layer normal login has a session timeout value returned on response body of generally of 30 minutes. Does SSO login have any session timeout?