Skip to Content

Sample: How to consume Service Layer oData services from .NET via WCF

Some weeks ago I published a blog explaining how to consume Service Layer oData services from .NET via WC, please read it as introduction to this blog and sample:

How to consume Service Layer oData services from .NET via WCF

In this new blog I want to announce that we published 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!

You must be Logged on to comment or reply to a post.
    • Hi Jhonmar,

      The Service Layer metadata generates entitites for each one of your UDTs and UDOs. Please check the generated objects in WCF and verify the corresponding objects have been generated for each one of your UDTs and UDOs.



  • I have been facing same challenge as mentioned in the original post. I have made all recommended changes in "b1s.conf" file & also restarted the service but still I am not able to have service reference in my application. Getting below mentioned error:

    Metadata contains a reference that cannot be resolved: 'https://hanaaisi2:50000/b1s/v1'.

    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.

    The remote server returned an error: (401) Unauthorized.

  • Hi,

    I used a ServiceLayer in my C# Add-on

    I have a problem with Cyrillic symbols.

    I try to this query:

    currentServiceContainer.ServiceCalls.Where(cursor => cursor.CustomerCode.Equals("Абвгде")).ToArray();

    And I have an error:

    "{...\"message\"...: \"Query string error - no matched single quote is found\"..."


    Please, help me



  • Hi

    This client have 13 databases on 3 HANA servers

    Ramdomly the conexion failed at least one database.

    System.Data.Services.Client.DataServiceQueryException: Error al procesar esta solicitud. —> System.Data.Services.Client.DataServiceClientException: {
    “error” : {
    “code” : -111,
    “message” : {
    “lang” : “en-us”,
    value” : “Unable to access SBO-Common database”

    System.Data.Services.Client.DataServiceQueryException: Error al procesar esta solicitud. —> System.Data.Services.Client.DataServiceClientException: {
    “error” : {
    “code” : -1,
    “message” : {
    “lang” : “en-us”,
             “value” : “Unknown error”

    Best regards

    • Hi Jose,

      Yes, if you look at the metadata file you will see UserObjects object is available and works the same as for the DI API.
      As soon as a UDF is added to a B1 object the corresponding properties will be available on Service Layer.


      • Hello Maria,

        Great contribution you have here, unfortunately I couldn't make it work, it gives me this error after login in and retrieving initial data

           "error" : {
              "code" : -1001,
              "message" : {
                 "lang" : "en-us",
                 "value" : "Authorization header not found"


        Any idea what it might be? Hope you can put me in the right direction here


        Best Regards,


  • Hello Maria,

    Do you know how to convert this part to VB.Net ?

    this code is on servicelayerservices.cs

    Because I've Tried,

    currentServiceContainer.SendingRequest = currentServiceContainer_SendingRequest

    it got an error on



    public void InitServiceContainer(string strServerURL)

    //Attach or revise the headers for carring the sesssion id, or set the paging size.
    currentServiceContainer.SendingRequest += currentServiceContainer_SendingRequest;
    currentServiceContainer.ReceivingResponse += currentServiceContainer_ReceivingResponse;

    //work around WCF client cache mechanism.
    currentServiceContainer.MergeOption = MergeOption.OverwriteChanges;

    //SSL, TLS certificate
    ServicePointManager.ServerCertificateValidationCallback += RemoteSSLTLSCertificateValidate;



  • This demo application is of really a great help for mobile/Xamarin/C# developers. I found a couple of errors in the Batch Query sample, though, so I have fixed them in FormSboServiceLayer.cs. I’ve included the $top=3 option, too, to reduce the volume of data.

    Uri uriOrder = new Uri(strURL + "Orders?$top=3&$filter=DocEntry gt 10 and DocEntry lt 100");
    Uri uriBps = new Uri(strURL + "BusinessPartners?top=3&$select=CardCode,CardName,CardType");
    Uri uriItems = new Uri(strURL + "Items?$top=3");

    Fiddler was of really great help.



    Hello @mariatrinidad.martinezgea .

    I’m trying to create a WCF WebService on C# using the code you provide as an example. I was able to connect/disconnect to B1 and add Documents and JournalEntries. So far so good. But, I can’t find (or don’t know) how to execute a custom query. In my case, I need to consult the value of a UDF in a UDT. Just like “SELECT U_UDF FROM @UDT WHERE Code = ‘1’”.

    I just read on the documentation that you can only access UDT that are defined as “No Object” type. In my case this UDT is defined with Autoincrement number.

    How can I do this?. Do you have any example on C# (or VB) in order to do this?. We’re in 9.2 PL9.


    Many Thanks!


    José Antonio Salgueiro


  • Hello Maria,


    I’m trying to modify your example to support this option:  B1S-ReplaceCollectionsOnPatch=true.

    But i’m not sure where can we put this parameter in the request.


    I want to manage the allocated batches in the order items, and when I save the document I add, remove or update batches in the items of the order, the Service Layer does not return any error, but also it did not changed nothing in the allocated batches.

    Can you help me with this?


    Thank you.


    Best regards,

    Luis Raposo

  • Hello Mario,


    I want to create a sales quotations module using service layer.Please help to this. In your sample there is no option to create a sales quotation.please do the needfull