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,