Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
Showing results for 
Search instead for 
Did you mean: 
Product and Topic Expert
Product and Topic Expert
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)

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
1 Comment