4.2.6 Retrieve a Data Service's Metadata Document (CSDL)

The following example illustrates the exchange of messages that is required for a client to obtain a description document of a data service, as specified in RetrieveServiceMetadata Request (section 2.2.7.2.7).

The following data service metadata document contains customizable feed property mappings that are supported only in OData 2.0 and OData 3.0.

The data service metadata document also contains named resource streams that are supported only in OData 3.0.

Request:

 GET /service.svc/$metadata HTTP/1.1
 Host: host
 Accept: application/xml
 DataServiceVersion: 1.0
 MaxDataServiceVersion: 3.0

Response:

 HTTP/1.1 200 OK
 Date: Fri, 12 Dec 2008 17:17:11 GMT
 Content-Type: application/xml
 Content-Length: nnn
 DataServiceVersion: 3.0
  
 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
 <edmx:Edmx Version="1.0" 
        xmlns:edmx="http://schemas.microsoft.com/ado/2010/02/edmx"
        xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
 <edmx:DataServices m:DataServiceVersion="3.0">
    <Schema Namespace="SampleModel"
      xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
       <EntityContainer Name="SampleEntities"
                        m:IsDefaultEntityContainer="true">
         <EntitySet Name="Customers" EntityType="SampleModel.Customer" />
         <EntitySet Name="Employees" EntityType="SampleModel.Employee" />
         <EntitySet Name="Orders" EntityType="SampleModel.Order" />
         <EntitySet Name="OrderLines" EntityType="SampleModel.OrderLine" />  
         <EntitySet Name="Photos" EntityType="SampleModel.Photo" />  
         <AssociationSet Name="Orders_Customers"
              Association="SampleModel.Orders_Customers">
             <End Role="Customers" EntitySet="Customers" />
             <End Role="Orders" EntitySet="Orders" />
         </AssociationSet>
         <AssociationSet Name="OrderLines_Orders"
              Association="SampleModel.OrderLines_Orders">
             <End Role="OrderLine" EntitySet="OrderLines" />
             <End Role="Order" EntitySet="Orders" />
         </AssociationSet>
         <FunctionImport Name="CustomersByCity"
                         EntitySet="Customers"
                         ReturnType="Collection(SampleModel.Customer)"
                         m:HttpMethod="GET">
            <Parameter Name="city" Type="Edm.String" Mode="In" />
         </FunctionImport>
         <FunctionImport Name="GetRelatedCustomers"
                         EntitySet="Customers"
                         IsBindable="true" 
                         ReturnType="Collection(SampleModel.Customer)"
                         IsSideEffecting="false">
            <Parameter Name="company" Type="SampleModel.Company" Mode="In" />
         </FunctionImport>
         <FunctionImport Name="CreateOrder"
                         EntitySet="Orders"
                         IsBindable="true"
                         IsSideEffecting="true"
                         m:IsAlwaysBindable="true">
            <Parameter Name="customer" Type="SampleModel.Customer" Mode="In" />
            <Parameter Name="quantity" Type="Edm.Int32" Mode="In" />
            <Parameter Name="discountCode" Type="Edm.String" Mode="In" />
         </FunctionImport>
       </EntityContainer>
       <EntityType Name="Order">
         <Key>
           <PropertyRef Name="OrderID" />
         </Key>
         <Property Name="OrderID" Type="Edm.Int32" Nullable="false" />
         <Property Name="ShippedDate" Type="Edm.DateTime" Nullable="true"
            DateTimeKind="Unspecified" PreserveSeconds="true" />
         <NavigationProperty Name="Customer"
            Relationship="SampleModel.Orders_Customers"
            FromRole="Order" ToRole="Customer" />
         <NavigationProperty Name="OrderLines"
            Relationship="SampleModel.OrderLines_Orders"
            FromRole="Order" ToRole="OrderLine" />
       </EntityType>
       <EntityType Name="OrderLine">
         <Key>
           <PropertyRef Name="OrderLineID" />
         </Key>
         <Property Name="OrderLineID" Type="Edm.Int32" Nullable="false" />
         <Property Name="Quantity" Type="Edm.Int32" Nullable="false" />
         <Property Name="UnitPrice" Type="Edm.Decimal" Nullable="false" />
         <NavigationProperty Name="Order"
            Relationship="SampleModel.OrderLines_Orders"
            FromRole="OrderLine" ToRole="Order" />
       </EntityType>
       <EntityType Name="Customer">
         <Key>
           <PropertyRef Name="CustomerID" />
         </Key>
         <Property Name="CustomerID" Type="Edm.String" Nullable="false"
            MaxLength="5" Unicode="true" FixedLength="true" />
         <Property Name="CompanyName" Type="Edm.String" Nullable="false"
            MaxLength="40" Unicode="true" FixedLength="false" />
         <Property Name="Address" Type="Sample.CAddress" Nullable="true" />
         <Property Name="Version" Type="Edm.Binary" Nullable="true" MaxLength="8"
            FixedLength="true" ConcurrencyMode="Fixed" />
         <NavigationProperty Name="Orders"
            Relationship="SampleModel.Orders_Customers"
            FromRole="Customer" ToRole="Order" />
       </EntityType>
       <EntityType Name="Employee" m:FC_KeepInContent="true"
            m:FC_TargetPath="Location" m:FC_SourcePath="Address/City" 
            m:FC_NsUri="http://www.microsoft.com" m:FC_NsPrefix="emp">
         <Key>
           <PropertyRef Name="EmployeeID" />
         </Key>
         <Property Name="EmployeeID" Type="Edm.String" Nullable="false"
            MaxLength="5" Unicode="true" FixedLength="true" />
         <Property Name="EmployeeName" Type="Edm.String" Nullable="false"
            MaxLength="40" Unicode="true" FixedLength="false" 
            m:FC_KeepInContent="false"          
            m:FC_TargetPath="SyndicationTitle"/>
         <Property Name="Address" Type="Sample.EAddress" Nullable="true" />
         <Property Name="Version" Type="Edm.Binary" Nullable="true" MaxLength="8"
            FixedLength="true" ConcurrencyMode="Fixed" />
       </EntityType>
       <EntityType Name="Company">
         <Key>
           <PropertyRef Name="CompanyID" />
         </Key>
         <Property Name="CompanyID" Type="Edm.String" Nullable="false"
            MaxLength="5" Unicode="true" FixedLength="true" />
         <Property Name="CompanySize" Type="Edm.String" Nullable="true"/>
       </EntityType>
  
       <EntityType Name="Photo" m:HasStream="true">
         <Key>
           <PropertyRef Name="ID" />
         </Key>
         <Property Name="ID" Type="Edm.Int32" Nullable="false" />
         <Property Name="Name" Type="Edm.String" Nullable="true" />
         <Property Name="Thumbnail" Type="Edm.Stream" />
         <Property Name="PrintReady" Type="Edm.Stream" />
       </EntityType>
  
       <ComplexType Name="CAddress">
         <Property Name="Street" Type="Edm.String" Unicode="true" />
         <Property Name="City" Type="Edm.String" Unicode="true"/>
       </ComplexType>
       <ComplexType Name="EAddress">
         <Property Name="Street" Type="Edm.String" Unicode="true" />
         <Property Name="City" Type="Edm.String" Unicode="true"/>
       </ComplexType>
       <Association Name="Orders_Customers">
         <End Role="Customer" Type="SampleModel.Customer"
              Multiplicity="0..1" />
         <End Role="Order" Type="SampleModel.Order" Multiplicity="*" />
       </Association>  
       <Association Name="OrderLines_Orders">
         <End Role="Order" Type="SampleModel.OrderLine"
              Multiplicity="*" />
         <End Role="OrderLine" Type="SampleModel.Order" Multiplicity="0..1" />
       </Association>
   </Schema>
  </edmx:DataServices>
 </edmx:Edmx>