Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DomSchmHopp opened this issue Mar 7, 2024 · 1 comment
Open

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

DomSchmHopp opened this issue Mar 7, 2024 · 1 comment

Comments

@DomSchmHopp
Copy link

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants