none
OData - ETag problem

    Question

  • Hi

    I am not that fluent in C# yet, but some day i might :P

    Hope someone can help me with the following, OData - ETab problem that i have..

    I need to update, data i a Dynamics NAV through an OData connection, so I am writing a test in C#.

    The connection is working, i can connect, and get data from my OData source, so there is no problem with the connector etc.

    But when i want to update data back to the OData service, then i get the following:
    {"odata.error":{"code":"","message":{"lang":"da-DK","value":"The etag value '\"'36%3BJAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA%3D%3D7%3B10073950%3B'\"' specified in one of the request headers is not valid. Please make sure only one etag value is specified and is valid."}}}

    What i can see the ETag should be right, the following is from my get query:
    "ETag": "36;JAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA==7;10073950;"

    I think that the problem is that when i build the ETag, when i look at it in the debugger, then it looks like there is an \" as the representation of " in the text string, that is also what i can see in the error message..

                string sETag = String.Format("\"'{0}'\"", Uri.EscapeDataString("36;JAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA==7;10073950;"));
    
                EntityTagHeaderValue Etag = new EntityTagHeaderValue(sETag);

    I am a bit lost here, so can anyone help me how do i format the ETag string, so it only contains the characters that i want in my request?

    /Graves

    Wednesday, April 12, 2017 9:11 AM

Answers

  • Hi

    Thanks for your answer :-)

    I ended with this solution, it solved the equation with this strange combination, and then i found that part of my problem also was, that i should specify the "Weak" parameter on the EntityTagHeaderValue.

    string sETag = '"' + "'" + Uri.EscapeDataString("36;JAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA==7;10073950;") + "'" + '"';
    
    EntityTagHeaderValue Etag = new EntityTagHeaderValue(sETag,true);
    /Graves

    • Marked as answer by Kilsgaard Wednesday, April 12, 2017 1:10 PM
    Wednesday, April 12, 2017 1:10 PM

All replies

  • Try these variants:

       string sETag = String.Format("'{0}'", …

       string sETag = Uri.EscapeDataString("36;JAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA==7;10073950;");

       string sETag = "36;JAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA==7;10073950;";

    Wednesday, April 12, 2017 10:53 AM
  • Hi

    Thanks for your answer :-)

    I ended with this solution, it solved the equation with this strange combination, and then i found that part of my problem also was, that i should specify the "Weak" parameter on the EntityTagHeaderValue.

    string sETag = '"' + "'" + Uri.EscapeDataString("36;JAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA==7;10073950;") + "'" + '"';
    
    EntityTagHeaderValue Etag = new EntityTagHeaderValue(sETag,true);
    /Graves

    • Marked as answer by Kilsgaard Wednesday, April 12, 2017 1:10 PM
    Wednesday, April 12, 2017 1:10 PM