web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

OData Client Web Service Issue

(0) ShareShare
ReportReport
Posted on by 10

OData Client Query Issue

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);

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

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

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Ahmad,

    Please check the URL you are passing. Also, please generate the Odata cient code using version Odata V4.

  • @frankrasta Profile Picture
    30 on at

    Hi:

    Try with this code:

    ServicePointManager.Expect100Continue = true;

               ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

               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);

               });

    Regards.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans