Skip to Content

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.

DOWNLOAD IT FROM HERE

Enjoy it!

To report this post you need to login first.

17 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    Hi, i am using service layer to add sales order documnet from an addon program.

    and now i got some problem.so i want to refer to your sample code.

    But i can not open  the download link . can you send me a copy. David.Sun@sapsoft.net .

    Thank you very much,

    (0) 
    1. Maria Trinidad MARTINEZ GEA Post author

      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.

      Regards,

      Trinidad.

      (0) 
  2. Deepak Salhotra

    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.

    (0) 
  3. Former Member

    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\”…”

    /wp-content/uploads/2016/05/1111_957680.jpg

    Please, help me

    Thanks,

    Irina

    (0) 
  4. Former Member

    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

    (0) 
    1. Maria Trinidad MARTINEZ GEA Post author

      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.

      Regards,
      Trinidad.

      (0) 
      1. Former Member

        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,

        Jose

        (0) 
  5. Former Member

    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 VB.net

     

     

    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;

     

     

    (0) 
  6. Miklós Németh

    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.

     

    (0) 
  7. Jose Antonio Salgueiro

     

    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!

    K.R

    José Antonio Salgueiro

     

    (0) 

Leave a Reply