OData Client Query Issue

Ahmad Khan 1 Reputation point
2020-09-29T15:30:02.667+00:00

I have a OData Web service Dynamics 365 and write a code to consume that Odata Web service as follows

Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
var context = new Resources(oDataUri);

            context.SendingRequest2 += new EventHandler<SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e)
            {
                var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true);
                e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);                  
            });

var jobs = await context.JobTypes.ExecuteAsync();
foreach (var job in jobs)
{
Console.WriteLine("Description: {0}", job.Description);
}

Following is the Metada string

<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="Microsoft.Dynamics.DataEntities" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="JobType">
<Key>
<PropertyRef Name="JobTypeId"/>
</Key>
<Property Name="JobTypeId" Type="Edm.String" Nullable="false">
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.LabelId" String="@SYS328398"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.ConfigurationKeyEnabled" Bool="true"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.AllowEdit" Bool="false"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.IsRequired" Bool="true"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.AXType">
<EnumMember>Microsoft.Dynamics.OData.Core.V1.AXType/String</EnumMember>
</Annotation>
</Property>
<Property Name="Description" Type="Edm.String">
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.LabelId" String="@SYS7576"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.ConfigurationKeyEnabled" Bool="true"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.IsRequired" Bool="true"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.AXType">
<EnumMember>Microsoft.Dynamics.OData.Core.V1.AXType/String</EnumMember>
</Annotation>
</Property>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.LabelId" String="@SYS117155"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.ConfigurationKeyEnabled" Bool="true"/>
<Annotation Term="Microsoft.Dynamics.OData.Core.V1.LookupGroup">
<Collection>
<String>JobTypeId</String>
<String>Description</String>
</Collection>
</Annotation>
</EntityType>
<EntityContainer Name="Resources">
<EntitySet Name="JobTypes" EntityType="Microsoft.Dynamics.DataEntities.JobType" />
</EntityContainer>
</Schema>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Microsoft.Dynamics.OData.Core.V1">
<EnumType Name="AXType">
<Member Name="Container" Value="0"/>
<Member Name="Date" Value="1"/>
<Member Name="Enum" Value="2"/>
<Member Name="Guid" Value="3"/>
<Member Name="Int32" Value="4"/>
<Member Name="Int64" Value="5"/>
<Member Name="Real" Value="6"/>
<Member Name="Record" Value="7"/>
<Member Name="String" Value="8"/>
<Member Name="Time" Value="9"/>
<Member Name="UtcDateTime" Value="10"/>
<Member Name="Void" Value="11"/>
</EnumType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

When I run application it successfully authenticate by when query data it generates the following error
I have tried OData V4 Client Code generator and OData V3 Client Code generator.

"The response payload is a not a valid response payload. Please make sure that th
e top level element is a valid Atom or JSON element or belongs to 'http://docs.o
asis-open.org/odata/ns/data' namespace."

Please help

Thank you
Ahmad

Community Center Not monitored
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JamesTran-MSFT 36,906 Reputation points Microsoft Employee Moderator
    2020-09-29T23:40:30.577+00:00

    @Ahmad Khan
    Based off your error message, I was able to find a similar issue that might help point you in the right direction. Additionally, you can reach out to our Stack Overflow OData forum.

    I hope this helps! If you have any other questions please let me know.
    Thank you for your time and patience throughout this issue.

    ----------

    If any reply/answer helped resolve your question, please remember to "mark as answer" so that others in the community facing similar issues can easily find the solution.


  2. JamesTran-MSFT 36,906 Reputation points Microsoft Employee Moderator
    2020-10-08T19:34:02.287+00:00

    @Ahmad Khan
    I just wanted to check in and see if you required additional assistance or if you were able to resolve this issue?

    I did receive a response from our engineering team saying this is a Dynamics365 issue, we've added the closest tag within Q&A for that team. However, you might get a better response if you engage our engineers within the Stack Overflow OData forum, or within the Microsoft Dynamics 365 Community.

    If you're still having issue even after reaching out to the respective forums, please feel free to send me an email with the below information. This way I can enable your subscription for a one-time free technical support request.

    Email: AzCommunity@microsoft.com
    Subject: ATTN - James Tran
    Body:
    Subscription ID
    Link to this thread.

    If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.