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

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.

DOWNLOAD IT FROM HERE

Enjoy it!

Assigned Tags

      20 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      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,

      Author's profile photo Former Member
      Former Member

      I have got it. Thank you all the same.

      Author's profile photo Former Member
      Former Member

      Hi.

      how do I query, insert , and delete records from a user tabal ?, is this possible?


      Thanks

      Author's profile photo Maria Trinidad MARTINEZ GEA
      Maria Trinidad MARTINEZ GEA
      Blog 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.

      Author's profile photo Deepak Salhotra
      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.

      Author's profile photo Hackerman temper
      Hackerman temper

      The same thing happens to me, my God, where is the solution please?

      Author's profile photo Former Member
      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

      Author's profile photo Felipe Loyola
      Felipe Loyola

      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

      Author's profile photo Francisco Velazquez Ruiz
      Francisco Velazquez Ruiz

      Hi Maria, could you please provide me the new link for the blog post or  email me the code sample, my e-mail address is fvelazquez@bexap.com.

       

      Best Regards

       

      Author's profile photo Former Member
      Former Member

      Can you add a user field to a business partner?

      Author's profile photo Maria Trinidad MARTINEZ GEA
      Maria Trinidad MARTINEZ GEA
      Blog 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.

      Author's profile photo Former Member
      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

      Author's profile photo Former Member
      Former Member

      I solved it looking at the Uri it was passing!

      Author's profile photo G. Snel
      G. Snel

      Hi @mariatrinidad.martinezgea,

       

      How can can I read AdminInfo with CompanyService_GetAdminInfo in WCF?

      Via Postman I can see the data, but I cannot figure out how to do it with WCF?

       

      Gerrit

      Author's profile photo Former Member
      Former Member

      Hi

      Allow global transactions grouping several operations?

       

      slds

       

      Author's profile photo Hendra Prakasa Notosusilo
      Hendra Prakasa Notosusilo

      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;

       

       

      Author's profile photo Miklós Németh
      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.

       

      Author's profile photo Jose Antonio Salgueiro
      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

       

      Author's profile photo Luis Raposo
      Luis Raposo

      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

      Author's profile photo Manikandan Dillibabu
      Manikandan Dillibabu

      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