Skip to Content

How to consume HANA Service Layer call GET CompanyService_GetAdminInfo using C#?


We recently started developing with HANA Service Layer calls in C#. We found the following site and used the sample code to get started on our own project.

Everything went well until we needed to retrieve Company information.

// This call has no problems
var uri = new Uri(BaseUrl + @"VatGroups('A2')");
var vatGroup = serviceLayer.Execute<VatGroup>(uri, "GET", true).SingleOrDefault();

// This call gives an error
uri = new Uri(BaseUrl + "CompanyService_GetAdminInfo"); 
var admin = serviceLayer.Execute<AdminInfo>(uri, "POST", true).SingleOrDefault();

We get the following error:
The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom or JSON element or belongs to '' namespace.

When i use Postman to do the same call, it has no problems!?

As you can see on the aforementioned URL i already asked there and i have gotten the suggestion to change my code to (she uses more code, but this should be the same):

var uri = new Uri(BaseUrl + "CompanyService_GetAdminInfo");
BodyOperationParameter[] body = null;
var admin = (AdminInfo)serviceLayer.Execute<AdminInfo>(uri, "POST", true, body).SingleOrDefault();

Unfortunately this did not do the trick...

Does anybody have any idea why i get this error on certain calls and how i can get it working?

I am using SAP 9.2 PL 08 and Visual Studio 2015.

I wanted to upload my project, but it seems that is not possible, so i will upload the source for a Console application (Program.cs => program.txt).

You will have to add a "Service Reference" linked to your "https://<your server ip>:50000/b1s/v1/$metadata" (don't forget to do a Login call first in (for example) Postman) and most likely have to add some references. You also will have to change some of the const values in the top...

If more information is required, please ask...

With kind regards,

Ruben Pol

program.txt (8.3 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Feb 06, 2018 at 07:16 AM

    Hi Ruben,

    Our development team is investigating the issue.

    Seems like WCF expects Service Layer returns something like :
    "odata.metadata": "$metadata#SAPB1.CompanyInfo",
    "Version": 930130,
    "EnableExpensesManagement": "tNO",
    "EnableAccountSegmentation": "tYES",
    "EnableBillOfExchange": "tNO",
    "BaseDateForExchangeRate": "bdr_PostingDate",
    "BISRBankActKey": null,
    "BISRBankCountry": null,

    But currenlty, "odata.metadata": "$metadata#SAPB1.CompanyInfo" is missing.

    Should be fixed in a coming patch, I'll keep you updated.


    Add comment
    10|10000 characters needed characters exceeded

  • Jan 22, 2018 at 10:18 AM

    Hi Ruben,

    I have tested in my environment and I can also reproduce it.

    I remember (if I'm not mistaken) having the CompanyService_GetCompanyInfo working fine in my WCF sample project but now I cannot.

    I have checked and the request is correctly sent to Service Layer and the response 200 OK is correctly received by .NET. the problem is that .NET while trying to extract the response throws an exception.

    I have compared this Service with the Login service that works fine with WCF and I have noticed the Login service response is a B1Session EntityType

    <EntityType Name="B1Session">    <Key>  
        <PropertyRef Name="SessionId"/>  
      <Property Name="SessionId" Nullable="false" Type="Edm.String"/>  
      <Property Name="Version" Type="Edm.String"/>  
      <Property Name="SessionTimeout" Type="Edm.Int32"/></EntityType>

    While the CompanyService_GetCompanyInfo returns a ComanyInfo ComplexType

    <ComplexType Name="CompanyInfo">  
      <Property Name="Version" Nullable="false" Type="Edm.Int32"/>  
      <Property Name="EnableExpensesManagement" Type="Edm.String"/>  
      <Property Name="EnableAccountSegmentation" Type="Edm.String"/>

    I'm now trying to find out why the ComplexType is creating such problems with .NET WCF...


    Add comment
    10|10000 characters needed characters exceeded

    • Hi Trinidad,

      Thanks for the research so far... I am "glad" to hear you can at least reproduce my problem. Hopefully soon it will be working as expected...

      With kind regards,

      Ruben Pol