Search code examples
odataasp.net-web-api2

Odata Client Code Generator-Unable to generate .cs file


I have a WPF clinet and I am using Odata Client Code Generator for creating a client of an odata service using Web Api 2.

I have followed this tutorial: http://blogs.msdn.com/b/odatateam/archive/2014/03/12/how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class.aspxd

The problem is that I am getting an empty .cs file that is being created by following the steps described in the tutorial(the link of which is given above).

The MatadataDocumentUri that I am using is: http://localhost:56045/odata

Is there something I am missing?

Here is the Metadata by using http://localhost:56045/odata/$metadata:

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="RestApiServer.Models">
<EntityType Name="User">
<Key>
<PropertyRef Name="UserId"/>
</Key>
<Property Name="UserId" Type="Edm.Int32" Nullable="false"/>
<Property Name="UserName" Type="Edm.String"/>
<Property Name="UserType" Type="Edm.String"/>
<NavigationProperty Name="UserAddress" Relationship="RestApiServer.Models.RestApiServer_Models_User_UserAddress_RestApiServer_Models_UserAddress_UserAddressPartner" ToRole="UserAddress" FromRole="UserAddressPartner"/>
</EntityType>
<EntityType Name="UserAddress">
<Property Name="UserId" Type="Edm.Int32" Nullable="false"/>
<Property Name="UserAddress1" Type="Edm.String"/>
<NavigationProperty Name="User" Relationship="RestApiServer.Models.RestApiServer_Models_UserAddress_User_RestApiServer_Models_User_UserPartner" ToRole="User" FromRole="UserPartner"/>
</EntityType>
<Association Name="RestApiServer_Models_User_UserAddress_RestApiServer_Models_UserAddress_UserAddressPartner">
<End Type="RestApiServer.Models.UserAddress" Role="UserAddress" Multiplicity="0..1"/>
<End Type="RestApiServer.Models.User" Role="UserAddressPartner" Multiplicity="0..1"/>
</Association>
<Association Name="RestApiServer_Models_UserAddress_User_RestApiServer_Models_User_UserPartner">
<End Type="RestApiServer.Models.User" Role="User" Multiplicity="0..1"/>
<End Type="RestApiServer.Models.UserAddress" Role="UserPartner" Multiplicity="0..1"/>
</Association>
</Schema>
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="Default">
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="Users" EntityType="RestApiServer.Models.User"/>
<EntitySet Name="UserAddresses" EntityType="RestApiServer.Models.UserAddress"/>
<AssociationSet Name="RestApiServer_Models_User_UserAddress_RestApiServer_Models_UserAddress_UserAddressPartnerSet" Association="RestApiServer.Models.RestApiServer_Models_User_UserAddress_RestApiServer_Models_UserAddress_UserAddressPartner">
<End Role="UserAddressPartner" EntitySet="Users"/>
<End Role="UserAddress" EntitySet="UserAddresses"/>
</AssociationSet>
<AssociationSet Name="RestApiServer_Models_UserAddress_User_RestApiServer_Models_User_UserPartnerSet" Association="RestApiServer.Models.RestApiServer_Models_UserAddress_User_RestApiServer_Models_User_UserPartner">
<End Role="UserPartner" EntitySet="UserAddresses"/>
<End Role="User" EntitySet="Users"/>
</AssociationSet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

Solution

  • Your metadata is actually a V3 format metadata. Please check: http://services.odata.org/V4/OData/OData.svc/$metadata, the root is:

    <edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    

    and for http://services.odata.org/V3/OData/OData.svc/$metadata

    <edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
    

    So your service is actually a OData V3 service, which our client generator does not support yet.