Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transformation error when running OData v4 Client Code Generator

Tags:

c#

odata

I have an OData service that returns the following from the /$metadata endpoint:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
    <Schema Namespace="(...)" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
      <!-- ... -->
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

When I attempt to run the OData v4 Client Code Generator (v2.3.0) against this XML file, I get the following errors:

Warning: Running transformation: The element 'edmx:Edmx' was unexpected for the root element. The root element should be Edmx.

Warning: The 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata:DataServiceVersion' attribute is not declared.

I also see only an empty .cs output file.

I've tried removing the edmx: namespace prefix from the <Edmx> and <DataServices> elements, making that namespace the default, and adjusting the prefixes on the remaining elements, but that doesn't work either:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Edmx Version="1.0" xmlns="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:edm="http://schemas.microsoft.com/ado/2008/09/edm">
  <DataServices m:DataServiceVersion="1.0">
    <edm:Schema Namespace="(...)">
      <!-- ... -->
    </edm:Schema>
  </DataServices>
</Edmx>
like image 684
Lars Kemmann Avatar asked May 08 '15 19:05

Lars Kemmann


1 Answers

Okay, it looks like the problem might be the version of OData that the service is exposing -- namely, OData v1.0. The edm namespace being defined is http://schemas.microsoft.com/ado/2006/04/edm. See OData Version 4.0 Part 3: Common Schema Definition Language (CSDL), §2.2:

Elements and attributes that define the entity model exposed by the OData Service are qualified with the Entity Data Model namespace:

  • http://docs.oasis-open.org/odata/ns/edm

Prior versions of CSDL used the following namespaces for EDM:

  • CSDL version 1.0: http://schemas.microsoft.com/ado/2006/04/edm
  • CSDL version 1.1: http://schemas.microsoft.com/ado/2007/05/edm
  • CSDL version 1.2: http://schemas.microsoft.com/ado/2008/01/edm
  • CSDL version 2.0: http://schemas.microsoft.com/ado/2008/09/edm
  • CSDL version 3.0: http://schemas.microsoft.com/ado/2009/11/edm

Using the Add Service Reference tool in Visual Studio 2013 (optionally with this update installed) solves the problem of generating client code for this OData service.

like image 128
Lars Kemmann Avatar answered Nov 12 '22 07:11

Lars Kemmann