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这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始 ...
随机推荐
- 【Machine Learning】决策树案例:基于python的商品购买能力预测系统
决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本 ...
- [干货来袭]C#6.0新特性
微软昨天发布了新的VS 2015 ..随之而来的还有很多很多东西... .NET新版本 ASP.NET新版本...等等..太多..实在没消化.. 分享一下也是昨天发布的新的C#6.0的部分新特性吧.. ...
- notepad++设置默认打开txt文件失效的解决方法
1.系统环境 win10企业版,64位系统 2.初步设置 设置txt默认为notepad++打开,菜单:设置->首选项->文件关联 选择对应的文件扩展,点击"关闭"按钮 ...
- ABAP实现屏幕自己刷新和跳转功能
ABAP开发工程中,有时候需要让跳转出的屏幕自动实现跳转和刷新的功能,该功能的实现需要在屏幕PBO 里面调用相应的事件执行. 关键代码为: SET TITLEBAR ' 屏幕自动程序'. IF g_c ...
- python select网络编程详细介绍
刚看了反应堆模式的原理,特意复习了socket编程,本文主要介绍python的基本socket使用和select使用,主要用于了解socket通信过程 一.socket模块 socket - Low- ...
- Linux网络属性配置
目录 IP地址分类 如何将Linux主机接入到网络中 网络接口的命名方式 ifcfg系列命令 如何配置主机名 如何配置DNS服务器指向 iproute2系列命令 Linux管理网络服务 永久生效配置路 ...
- 从myeclipse导入eclipse,不能识别为web项目(java项目转为web项目)
1.进入项目目录,找到.project文件,打开. 2.找到<natures>...</natures>代码段. 3.在第2步的代码段中加入如下标签内容并保存: ...
- 按照Enterprise Integration Pattern搭建服务系统
在前一篇文章中,我们已经对Enterprise Integration Pattern中所包含的各个组成进行了简单地介绍.限于篇幅(20页Word以内),我并没有深入地讨论各个组成.但是如果要真正地按 ...
- Redola.Rpc 的一个小目标
Redola.Rpc 的一个小目标 Redola.Rpc 的一个小目标:20000 tps. Concurrency level: 8 threads Complete requests: 20000 ...
- RabbitMQ的安装过程
原创文章转载请注明出处:@协思, http://zeeman.cnblogs.com 网上一些安装教程都较为繁琐,实际上只需要两个RPM包,几分钟即可完成一台实例部署. 准备下载Erlang包: ht ...