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
In this blog I'll like to show you how to consume SAP Business One Service Layer oData sevices from a .NET application via WCF.

SAP Business One Service Layer is a new generation of extension API for consuming SAP Business One data and services. It builds on core protocols such as HTTP and OData, and provides a uniform way to expose full-featured business objects on top of a highly scalable and high-availability Web server. Currently, Service Layer supports OData version3, version 4, and a few selected OData client libraries, for example, WCF for .Net developers; data.js for JavaScript developers.

After installing SAP Business One Service Layer in your server (installed as part of the SAP Business One server components in the HANA Linux server) all documentation is available at the following link:

https://your_hana_server:50000 (your_hana_server is the name or IP of your HANA server)

Please also check the different documents and samples available in the main SAP Business One, version for SAP HANA Extensibility topics (http://scn.sap.com/docs/DOC-60454).

Development Environment

  1. Odata protocol version 3 is the highest version supported by WCF.

  2. You can choose to work with VS 2010, 2012 or 2013 for your daily work.

  3. As precondition, you need to get "WCF Data Services 5.6.0 Tools" installed in advance. You can get the installer from:

  4. Next section explains  how to consume Odata Services via WCF.

  5. You can use Json.Net [NewtonSoft.Json.Net.dll] library for object serialization.

  6. Service Layer server needs to be configured with the following properties in the file b1s.conf (located in the Service Layer installation folder ServiceLayer/conf):

    1. "MetadataWithoutSession": true  (not required anymore, see following steps)

    2. "WCFCompatible":true

After changing the configuration file you need to restart Service Layer by running the following command in /etc/init.d folder:
./b1s restart

How to consume Service Layer odata service via WCF

 Add the metadata as service or file directly by selecting “Add Service Reference” into your C#/.NET based Microsoft Visual Studio project, the metadata will be validated automatically.

Note: You have two options:

  1. Open a session with Service Layer before with the Login POST command, for example via PostMan or any other tool.Send a $metadata GET request with the B1S-WCFCompatible header property set to true.

Save the metadata response into an xml file.

Point to the metadata xml file from Microsoft Visual Studio Add Service Reference window:

2. Directly put the $metadata link into the Add Service Reference window (without opening a session before).

You will be prompted to enter a User name and a Password:

As there is no input for company name in WCF, the username and company must be combined as a User name.

User name: {"CompanyDB": "SBODEMOUS", "UserName": "manager"}
Password: your user password


Microsoft Visua Studio IDE will use a tool named “SvcUtil.exe” to validate the metadata XML and generate proxy class for your usage automatically if validate passed. You can find all classes in “ObjectBrowser”.



With the automatically generated proxy classes, you can program the required business logic of your application.


Sample Code

You can download a .NET sample code connecting to SAP Business One version for SAP HANA Service Layer and doing some operations like:

- Login/Logout

- Retreive the list of Business Partners and Items

- Add a Sales Order Document

- Update a Sales Order Document

- Get a specific Sales Order Document

- Close a Sales Order Document

- Get information via query filters to reduce the amount of data to be retrieved (for example not all fields but only CardCode, CardName fields required but the UI) to improve performances

- Send several queries via Batch in only one request

- Use pagination to retrieve all Orders page by page (user will not be able to see all pages at once and performances will be better if you retrieve page by page).


With this sample you will see how easy is to consume Service Layer Entities (what we are using to call objects in COM interface) and Actions (somehow equivalent to the DI API Services) by getting directly your hands in real .NET C# code.

Please use our standard SDK forum for questions/remarks on the SAP Business One version for SAP HANA Service Layer.


Enjoy it!