OData / ODataConnectedService

A Visual Studio extension for generating client code for OData Services
Other
79 stars 41 forks source link

JSON instead of XML body (SAP returns deformed syntax)? #382

Open DomSchmHopp opened 6 months ago

DomSchmHopp commented 6 months ago

Hi ! We have a very basic testing DataService which implements a simple test structure:

<EntityType Name="File" sap:content-version="1">
    <Key>
        <PropertyRef Name="InstanceId"/>
        <PropertyRef Name="AttachmentId"/>
        <PropertyRef Name="AttachmentCategory"/>
    </Key>
    <Property Name="InstanceId" Type="Edm.String" Nullable="false" sap:unicode="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
    <Property Name="AttachmentId" Type="Edm.String" Nullable="false" sap:unicode="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
    <Property Name="AttachmentCategory" Type="Edm.String" Nullable="false" sap:unicode="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
    <Property Name="FilenameWithExtension" Type="Edm.String" Nullable="false" sap:unicode="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
    <Property Name="Description" Type="Edm.String" Nullable="false" sap:unicode="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
    <Property Name="Mimetype" Type="Edm.String" Nullable="false" sap:unicode="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
    <Property Name="FileContentInBase64" Type="Edm.String" Nullable="false" sap:unicode="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
</EntityType>

When I use this Service like this:

                File tesFile = new File();
                tesFile.Description = "Daten aus C";
                tesFile.InstanceId = "8001080";
                tesFile.FilenameWithExtension = "HansWurst.txt";

                byte[] AsBytes = System.IO.File.ReadAllBytes(@"C:\Users\d-schmidt\PycharmProjects\odata\HansWurst.txt");
                string AsBase64String = Convert.ToBase64String(AsBytes);
                tesFile.FileContentInBase64 = AsBase64String;

                context.AddToFileSet(tesFile);
                var resp = context.SaveChanges();

It´s working so far, but SAP (Version 3) has a problem consuming the data.

We got this error message "Die Data-Services-Anforderung wurde wegen einer deformierten Syntax nicht verstanden." which is in english something like this The data services request was not understood due to a deformed syntax.

We figured out that the data is send in XML which SAP doesn´t like.

So can anyone give me a hint how to switch the payload data from XML to JSON? I know there is context.Format.UseJson(); but it requires a IEdmModel which I don´t have.

So if anyone could help me with this issue it would be much appreciated!

Dominik

marabooy commented 5 months ago

Hello @DomSchmHopp,

Thank you for reaching out! Could you please provide additional information and context regarding the specific API you are attempting to call on SAP's end? It would be greatly appreciated.

The issue you are encountering might be related to the format of the data being sent back to SAP, which could potentially be incompatible with the service's implementation expectations.

Additionally, consider capturing the data that OData is sending back to the service using Fiddler. Comparing it to an equivalent request made through Postman could help in debugging the issue. Sharing that with us will also enable us to debug this issue more effectively.