转发.

[Tutorial & Sample] How to use OData Client Code Generator to generate client-side proxy class

            Rate This         
                  layla liu

Avatar of layla liu

layla liu

1,150 Points                2                2                0                       
Recent Achievements           
Blogger II                                            Blog Conversation Starter                                            New Blog Commentator                                                           
View Profile           
            11 Mar 2014 10:48 AM             
 
  • Comments                 37
 

Edited on July 09, 2014 by updating “Add OData Client Proxy File” for V2.0.0 and adding "Appendix" part. Please refer to "OData Client Code Generator 2.0.0 release" for V2.0.0 release notes

Edited on Apr 29, 2014 by adding "Upgrade the Project Dependencies to the Most Recent Version" part.

In this tutorial, you will generate an OData client proxy class for an OData V4 service by “OData Client Code Generator”.

Install OData Client Code Generator

Start Visual Studio, from the TOOLS menu, select Extensions and Updates

In the left panel, expand Online -> Visual Studio Gallery. Search “OData Client Code Generator” in search box and Download the VSIX.

After the VSIX is downloaded, the installer page will show. Click Install.

Following dialog will show when installation finish. Click Close.

You need to restart Visual studio in order for the changes to take effect.

Create Your Application

Create your project. OData Client Code Generator works with any projects, but here, we take “Console Application” project for example

Add OData Client Proxy File

In Solution Explorer, right click you project name. Click Add->New Item.

In the left panel, expand Installed->Visual C# Items->Code. Choose “OData Client”, and rename your client file, such as “NorthwindProxy.tt”, and Click Add.

This step will add two files to your project

1. NorthwindProxy.tt contains all the configurations you need to set:

  • MetadataDocumentUri

Service document URI or service metadata URI or a file path of metadata local copy.

  • NamespacePrefix
    • The value will be used as the namespace of your client proxy when metadata contains only one schema.
    • The value will be added before namespaces of schemas when metadata contains several schemas.
    • The namespace in metadata will be used if the value is empty string.
  • EnableNamingAlias

This value will be used to enable naming alias. By default, it is to enable camel case on client side. But user can customize the naming alias logic.

2. NorthwindProxy.ttinclude is the T4 template for generating proxy file from metadata document.

Save the tt file, The generated cs file will show in Solution Explorer under the tt file.

Consume the generated code

Now, we have generated the client proxy for the service file. You can refer to it in your client code. Example.

Upgrade the Project Dependencies to the Most Recent Version

After all the steps above, you will find that the OData core and client libraries version 6.0.0 have been added into the references of this project.

If you want to upgrade the OData core and client libraries to the most recent version, you can use the NuGet Package Manager to do it.

In the solution explorer, right click the project and click "Manage NuGet Packages".


In the left panel, expand Update -> nuget.org. Select "OData Client for .NET" and click "Update".

After a few seconds, the "License Acceptance" dialog shows up. On this dialog, click "I Accept".

It will update these assemblies for this project. Then "Close" the dialog when it is done.

Check the OData core and client libraries assemblies, and it will show that you have upgraded them to the most recent version.

Appendix

The OData Code Generator V1.0.0 generates two files different from the V2.0.0 when adding new OData Client item template

1. NorthwindProxy.odata.config contains all the configurations you need to set:

  • MetadataDocumentUri

Service document URI or service metadata URI or a file path of metadata local copy.

  • NamespacePrefix
    • The value will be used as the namespace of your client proxy when metadata contains only one schema.
    • The value will be added before namespaces of schemas when metadata contains several schemas.
    • The namespace in metadata will be used if the value is empty string.

2. NorthwindProxy.tt is the T4 template for generating proxy file from metadata document.

Save your configuration file.

Re-trigger the code generation by right click at NorthwindProxy.tt, and select “Run Custom Tool”. The generated cs file will show in Solution Explorer under the tt file.

OData Client Code Generator的更多相关文章

  1. [转]OData的初步认识 OData v4 Client Code Generator

    本文转自:http://www.cnblogs.com/1zhk/p/5356053.html What – OData是什么? OData - Open Data Protocol,是一个设计和使用 ...

  2. ABP配套代码生成器(ABP Code Generator)帮助文档,实现快速开发

    ABP代码生成器介绍 针对abp这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始化.多语言.automapper自动注 ...

  3. Android项目实战(十九):Android Studio 优秀插件: Parcelable Code Generator

    Android Studio 优秀插件系列: Android Studio 优秀插件(一):GsonFormat Android Studio 优秀插件(二): Parcelable Code Gen ...

  4. JAVA 调用Axis2 code generator 生成的webservice

    以下代码为调用 JAVA 调用Axis2 code generator 生成的webservice的代码. package test; import java.rmi.RemoteException; ...

  5. DNN - Modules - QR Code Generator

    Dotnetnuke 平台上的二维码模块.支持DNN 7.x平台的安装 QR码(快速响应码)是二维条形码.随着移动设备市场正以快速的步伐,QR码正在成为非常重要的营销工具.与移动电话或平板电脑的扫描, ...

  6. there was an error running the selected code generator unable to retrieve metadata for

    there was an error running the selected code generator unable to retrieve metadata for PROBLEM: I ha ...

  7. Android开发的插件Code Generator与LayoutCreator的安装与使用,提升你的开发效率

    前言 大家好,给大家带来Android开发的插件Code Generator与LayoutCreator的安装与使用,提升你的开发效率的概述,希望你们喜欢 学习目标 掌握两个插件的安装和使用,能够实现 ...

  8. 安卓自动生成代码插件-Android code Generator(转)

    编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! 介绍 A ...

  9. 【2017年9月10日更新】ABP配套代码生成器(ABP Code Generator)帮助文档,实现快速开发

    ABP代码生成器介绍 ABP Code Generator 针对abp这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始 ...

随机推荐

  1. 应该是Angular2的一个bug?

    为了应对未来的趋势,及时赶上下一趟互联网技术,我最近也在通过具体项目研究angular2,首先必须要吐槽的是,学习angular2的成本本身不高,但是一堆的工具.配置实在让人 很是焦灼,就像asp.n ...

  2. 后缀数组的倍增算法(Prefix Doubling)

    后缀数组的倍增算法(Prefix Doubling) 文本内容除特殊注明外,均在知识共享署名-非商业性使用-相同方式共享 3.0协议下提供,附加条款亦可能应用. 最近在自学习BWT算法(Burrows ...

  3. php cryptr 加密函数

    class CryptHelper { /** * 加密 * @param unknown $password * @param unknown $salt * @return string */ p ...

  4. 【Java学习系列】第3课--Java 高级教程

    本文地址 可以拜读: 从零开始学 Java 分享提纲: 1. Java数据结构 2. Java 集合框架 3. Java泛型 4. Java序列化 5. Java网络编程 6. Java发送Email ...

  5. jquery-treegrid树状表格的使用(.Net平台)

    上一篇介绍了DataTable,这一篇在DT的基础之上再使用jquery的一款插件:treegrid,官网地址:http://maxazan.github.io/jquery-treegrid/ 一. ...

  6. arcgis api for js入门开发系列四地图查询(含源代码)

    备注:由于实现本篇功能的需求,修改了地图数据的dlsearch.mxd,然后更新了地图服务,需要的在文章最后有提供最新的mxd以及源代码下载的 上一篇实现了demo的地图工具栏,本篇新增地图查询功能, ...

  7. 记:MySQL 5.7.3.0 安装 全程截图

    前言: 下一个班快讲MySQL数据库了,正好把服务器里面的MySQL卸了重装了一下. 截个图,作为笔记.也正好留给需要的朋友们. 目录: 下载软件 运行安装程序 安装程序欢迎界面 许可协议 查找更新 ...

  8. 基于 SailingEase WinForm Framework 开发客户端程序(3:实现菜单/工具栏按钮的解耦及状态控制)

    本系列文章将详细阐述客户端应用程序的设计理念,实现方法. 本系列文章以  SailingEase WinForm Framework 为基础进行设计并实现,但其中的设计理念及方法,亦适用于任何类型的客 ...

  9. ABP(现代ASP.NET样板开发框架)系列之22、ABP展现层——导航栏设置

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之22.ABP展现层——导航栏设置 ABP是“ASP.NET Boilerplate Project (ASP.NE ...

  10. Entity Framework 6 Recipes 2nd Edition(10-1)译->非Code Frist方式返回一个实体集合

    存储过程 存储过程一直存在于任何一种关系型数据库中,如微软的SQL Server.存储过程是包含在数据库中的一些代码,通常为数据执行一些操作,它能为数据密集型计算提高性能,也能执行一些为业务逻辑. 当 ...