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









layla liu
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的更多相关文章
- [转]OData的初步认识 OData v4 Client Code Generator
本文转自:http://www.cnblogs.com/1zhk/p/5356053.html What – OData是什么? OData - Open Data Protocol,是一个设计和使用 ...
- ABP配套代码生成器(ABP Code Generator)帮助文档,实现快速开发
ABP代码生成器介绍 针对abp这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始化.多语言.automapper自动注 ...
- Android项目实战(十九):Android Studio 优秀插件: Parcelable Code Generator
Android Studio 优秀插件系列: Android Studio 优秀插件(一):GsonFormat Android Studio 优秀插件(二): Parcelable Code Gen ...
- JAVA 调用Axis2 code generator 生成的webservice
以下代码为调用 JAVA 调用Axis2 code generator 生成的webservice的代码. package test; import java.rmi.RemoteException; ...
- DNN - Modules - QR Code Generator
Dotnetnuke 平台上的二维码模块.支持DNN 7.x平台的安装 QR码(快速响应码)是二维条形码.随着移动设备市场正以快速的步伐,QR码正在成为非常重要的营销工具.与移动电话或平板电脑的扫描, ...
- 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 ...
- Android开发的插件Code Generator与LayoutCreator的安装与使用,提升你的开发效率
前言 大家好,给大家带来Android开发的插件Code Generator与LayoutCreator的安装与使用,提升你的开发效率的概述,希望你们喜欢 学习目标 掌握两个插件的安装和使用,能够实现 ...
- 安卓自动生成代码插件-Android code Generator(转)
编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! 介绍 A ...
- 【2017年9月10日更新】ABP配套代码生成器(ABP Code Generator)帮助文档,实现快速开发
ABP代码生成器介绍 ABP Code Generator 针对abp这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始 ...
随机推荐
- C#数组,List,Dictionary的相互转换
本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...
- SharpMap简析
1.背景 因为项目需求,需要基于开源项目来对SHP进行相关操作.涉及到的主要功能就是加载SHP读取其中的属性信息和几何信息.于是选择了Sharpmap来进行,在使用中对其相关功能做了初步了解,做个总结 ...
- bzoj3208--记忆化搜索
题目大意: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目. 我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑[严格大于] ...
- BPM始终服务于人,落脚于人
数字经济时代下,云计算.大数据.移动互联已经成为当下企业必须采取的武装力量.随着互联网+.中国制造2025.工业4.0等国家战略的引导与支持,无数的企业在这场数字化浪潮中使尽浑身解数,想要抓住机遇奋力 ...
- mysql数据库主从同步
环境: Mater: CentOS7.1 5.5.52-MariaDB 192.168.108.133 Slave: CentOS7.1 5.5.52-MariaDB 192.168. ...
- Linux 入门之网络配置
查看网络状态 ifconfig 修改网络参数 实验环境centos6.5,其他系统自行百度 ls /etc/sysconfig/network-scripts 显示所有文件, vi /etc/sysc ...
- ubuntu安装mysql
好记性不如烂笔头,记录一下,ubuntu安装mysql的指令. 安装MySQL: sudo apt-get install mysql-server sudo apt-get install mysq ...
- MongoDB基础
1.概念及特点 说明:由于部分语句中$ 符号无法正常显示,使用¥代表 概念 MongoDB是一个基于文档的分布式的开源的NoSQL数据库,文档的结构为BSON形式,每一个文档都有一个唯一的Object ...
- 舍弃Nunit拥抱Xunit
前言 今天与同事在讨论.Net下测试框架的时候,说到NUnit等大多数测试框架的SetUp以及TearDown方法并不是显得那么完美,所以在公司内部的项目中采用了Xunit框架.那么究竟是什么样的原因 ...
- Apache2.4卡住无法访问的解决……
早两个星期,搭建了一个项目管理平台--<如何安装一个优秀的BUG管理平台--真的是手把手教学!>.以前都是用apache2.2的,这次换了apache2.4.安装起来是没有问题的,结果运行 ...