Skip to Content
0

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

Jan 19 at 02:50 PM

409

avatar image

Hi,

We recently started developing with HANA Service Layer calls in C#. We found the following site https://blogs.sap.com/2015/07/15/how-to-consume-service-layer-odata-services-from-net-via-wcf/ 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 'http://schemas.microsoft.com/ado/2007/08/dataservices' 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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Maria Trinidad MARTINEZ GEA
Feb 06 at 07:16 AM
0

Hi Ruben,

Our development team is investigating the issue.

Seems like WCF expects Service Layer returns something like :
{
"odata.metadata": "http://10.58.136.174:9080/b1s/v1/$metadata#SAPB1.CompanyInfo",
"Version": 930130,
"EnableExpensesManagement": "tNO",
"EnableAccountSegmentation": "tYES",
"EnableBillOfExchange": "tNO",
"BaseDateForExchangeRate": "bdr_PostingDate",
"BISRBankActKey": null,
"BISRBankCountry": null,
....
}

But currenlty, "odata.metadata": "http://10.58.136.174:9080/b1s/v1/$metadata#SAPB1.CompanyInfo" is missing.

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

Regards,
Trinidad.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Trinindad,

We are having the same issue. Is this already fixed in a patch?

Thank you

Emanuel

0
Maria Trinidad MARTINEZ GEA
Jan 22 at 10:18 AM
0

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"/>  
  </Key>  
  <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...

Regards,
Trinidad.

Show 1 Share
10 |10000 characters needed characters left 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

0