OData v4 Client Code Generator

Microsoft Free

An item template that simplifies the process of accessing OData v4 services by generating C# and VB.Net client-side proxy classes.

(0) Review
Visual Studio
2013, 2012, 2010
Download (5,550)
E-mail Twitter del.icio.us Digg Facebook
Add to favorites
Q and A (8)
Sign in to write a review

Be the first to write a review.

Sign in to start a discussion

  • Async Query - help
    2 Posts | Last post August 11, 2014
    • Using Nuget package Console manager to install latest version in visual studio. 
      I cannot find Microsoft.OData.Client.QueryResult.
      App1.Container cont = new Container(new Uri("http://localhost:11373/"));
      cont.BeginExecute(new Uri("http://localhost:11373/"), OnQueryCompleted, "", "GET", null);
      public void OnQueryCompleted(IAsyncResult result)
      //result is of type Microsoft.OData.Client.QueryResult
      Any help?
    •   DataServiceQuery query = (DataServiceQuery)from c in container.TestEntity select c;
       var task = Task<IEnumerable>.Factory.FromAsync(query.BeginExecute, query.EndExecute, query);
                  await task;
                  var results = (Microsoft.OData.Client.QueryOperationResponse<TestEntity> )task.Result;
      This works correctly however.
  • Authentication support
    5 Posts | Last post August 05, 2014
    • As of version 2.0.0 there is not authentication support.  One must download the edmx as a file and then point the Text Template to the file.  This is an unnecessary step and was supported with OData 1-3 Update Service Reference built into VS. In the annoucement post on the OData Team blog (http://blogs.msdn.com/b/odatateam/archive/2014/07/09/odata-client-code-generator-2-0-0-release.aspx), the comments show several users are confused by this.  When will you be adding authentication support?  Are you currently working on this?  Thank you.
    • Hi AdamCaviness, thanks for your suggestions. We totally understand that it might not be that convenient for you to download the edmx to a local file, and the good news is that you can add the authentication support to T4 Template by yourself according to this tutorial http://blogs.msdn.com/b/odatateam/archive/2014/06/23/how-to-enable-authentication-for-metadata-documents-in-the-odata-client-code-generator.aspx
      Will this work for you?
    • @Junlin Zheng, Yes and thank you.
    • The link is only good for "Basic / Windows" authentication using "NetworkCredentials" and OData client < v2.0
      You can use a modified version to get "Forms" authentication to work.
      Also the original link is for the OData client v1 so you will have to make several adjustments to make it work correctly.
    • here is a help link for using "Forms" authentication with HttpWebRequest.
  • Bug when returning string array
    1 Posts | Last post July 31, 2014
    • Let's assume you have a odata service that returns a string array.
      If you try to run the OData client template against the OData service that returns the string array then the generated client code will have a have a namespace of "System" and a class of "String[]".
      This will of course break all code since it is using the "System" namespace.
      'Generation date: 7/31/2014 4:56:19 PM
      Namespace System
          '''There are no comments for String[] in the schema.
      	<Global.Microsoft.OData.Client.OriginalNameAttribute("String[]")>  _
          Partial Public Class String[]
              Implements Global.System.ComponentModel.INotifyPropertyChanged
              ''' <summary>
              ''' This event is raised when the value of the property is changed
              ''' </summary>
              <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.0.0")>  _
              Public Event PropertyChanged As Global.System.ComponentModel.PropertyChangedEventHandler Implements Global.System.ComponentModel.INotifyPropertyChanged.PropertyChanged
              ''' <summary>
              ''' The value of the property is changed
              ''' </summary>
              ''' <param name="property">property name</param>
              <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.0.0")>  _
              Protected Overridable Sub OnPropertyChanged(ByVal [property] As String)
                  If (Not (Me.PropertyChangedEvent) Is Nothing) Then
                      RaiseEvent PropertyChanged(Me, New Global.System.ComponentModel.PropertyChangedEventArgs([property]))
                  End If
              End Sub
          End Class
          ''' <summary>
          ''' Class containing all extension methods
          ''' </summary>
          Public Module ExtensionMethods
          End Module
      End Namespace
  • Bug when using Where clause and no results returned
    1 Posts | Last post July 21, 2014
    • Let's assume you have an odata model called customer with 2 properties. ID and CustomerName. Let's also assume there is NO customer record in the database that has an ID of 2.
      Now from the client you have the following:
      (from x in dbContext.Customer where x.ID = 2 select x.ID, x.CustomerName)
      This line of code will fail.
      "The 'ObjectContent`1' type failed to serialize the response body for content type" AND
      ""'SingleResult`1' cannot be serialized using the ODataMediaTypeFormatter."
      but if you change to code to use the "AddQueryOption" then it works.
      (from x in dbContext.Customer.AddQueryOption("$filter", "ID eq 2") select x.ID, x.CustomerName)
      works just fine.
      Please NOTE there is NO customer record of ID = 2 in the database.
  • Bug when selecting single property
    1 Posts | Last post July 21, 2014
    • Let's assume you have an odata model called customer with 2 properties. ID and CustomerName.
      Now from the client you have the following:
      (from x in dbContext.Customer where x.ID == 3 select x.ID)
      This line of code will fail.
      "No HTTP resource was found that matches the request URI 'http://localhost:63344/odata/Customer(3)/ID"
      but if you change to code to select more property then it works.
      (from x in dbContext.Customer where x.ID == 3 select x.ID, x.CustomerName)
      works just fine.
      Notice the URL has the select where the previous URL does not.
  • Customizable DataServiceContext class name
    5 Posts | Last post June 26, 2014
    • May you please add a Parameter to the config file for configuring the Context name? Such as <Parameter Name="DataServiceContextName" Value="Context" />  As it is now, the default name is "Container" and that word has too many connotations I'm afraid.  I would normally advocate users just change the tt for this sort of thing but this is such a common desire I'd recommend it be a Parameter.  Thanks.
    • The name of the context class is the same as the namespace defined in the metadata document. Such as for <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="ODataDemo">, the generated context class name is "ODataDemo". So if you own the implementation of the target OData service, you may want to change the namespace of the service to avoid such common name. Will this resolve your problem?
    • @Yi Ding, thanks for your response but this is not at all what I am seeing. My metadata document returns <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="WebApiServer.Data.Entities"> but the client DataServiceContext class is generated as  public partial class Container : global::Microsoft.OData.Client.DataServiceContext.  I thought possibly "Data" or "Entities" may be reserved keywords so I changed the namespace of the target OData service like so <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="WebApiServer"> and the client generated DataServiceContext class name remains Container!  
      At line 2062 of the T4 template I see:
          /// <summary>
          /// There are no comments for <#= containerName #> in the schema.
          /// </summary>
          public partial class <#= fixedContainerName #> : global::Microsoft.OData.Client.DataServiceContext
      I'm using VS2013 with Update 2.  On the server I'm using Web API 2.2 5.2.0-rtm with "OData team" libs of 6.4.0.
    • Sorry AdamCaviness that I made a mistake in this. The name of the class should be identical to the name of the EntityContainer (e.g. if there is <EntityContainer Name="InMemoryEntities"> in the metadata document then the generated class derived from DataServiceContext will be named "InMemoryEntities").
      In addition, the generated classes are contained in a namespace, whose name is configurable in the .tt file by modifying the "NamespacePrefix" in it. It's by default the same name as the name of the project in VS. So let's say you have this project named "DotNetClient" and a service whose entity container name is "Container", then the class generated that derives from DataSerivceContext will be "DotNetClient.Container". Thus, changing the namespace of the generated class also helps to resolve the possible name collision. Would this be OK?
    • @Yi Ding, thank you for the clarification.  It was not immediately discoverable to me how to change that EntityContainer name.  On my ODataConventionModelBuilder instance in the Web API server, I set the ContainerName property.  
      var builder = new ODataConventionModelBuilder();
      builder.ContainerName = "Context";
      Thanks again.
  • OData 4 has function binding but not the T4 template
    2 Posts | Last post June 10, 2014
    • The Web API 2.2 OData v4.0 supports functions defined on the model and the metadata show the supported functions but the T4 template does not generate any code based on this new OData v4.0 feature. Will functions be supported in the new proxy generated code?
    • Dear ImGonaRot, the functions will be supported by the OData Client Code Generator in our recent release in June.
  • OData v3.0 support
    2 Posts | Last post June 10, 2014
    • Is there a plan to support generating clients for endpoints of OData v3.0 format?
    • Dear nedarb760, currently in order to generate client side proxy for V3 services, you can use Add Service Reference: http://msdn.microsoft.com/en-us/library/bb628652.aspx