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这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始 ...
随机推荐
- PHP之用户验证和标签推荐的简单使用
本篇主要是讲解一些最简单的验证知识 效果图 bookmark_fns.php <?php require_once('output_fns.php'); require_once('db_fns ...
- 来吧,HTML5之一些注意事项
1.说什么是HTML HTML是一种超文本标记语言(Hyper Text Markup Language), 标记语言是一套标记标签(markup tag),用来描述网页的非编程语言. 2.标签特性: ...
- css常用hack
原文地址:css常用hack 突然想起今天早上在CNZZ看到的统计数据,使用IE6.7的用户比例还真多,看到之后我的心都碎了.微软都放弃了为毛还有这么多人不死心? 所以说,IE下的兼容还是得做的. – ...
- python 3.5 成功安装 scrapy 的步骤
http://www.cnblogs.com/hhh5460/p/5814275.html
- [修正] Firemonkey TFrame 存档后,下次载入某些事件连结会消失(但源码还在)
问题:Firemonkey TFrame 存档后,下次载入某些事件连结会消失(但源码还在) 解决:(暂时方法) type TTestFrame = class(TFrame) public const ...
- 驱动01.LED
1.写出leds_open,leds_write函数2.1告诉内核这几个函数的存在?定义一个结构体file_operations2.2把这个结构体告诉内核?用register_chrdev(major ...
- TDD原则
TDD 介绍 测试驱动开发,或者叫 TDD,是一个敏捷方法,通过确保在代码是先前手动编写测试用 例,用测试来驱动开发,从而翻转开发生命周期(它不只是作为一种校验工具). TDD 的原则很简单的: 只有 ...
- Threadlocal使用Case
Threadlocal能够为每个线程分配一份单独的副本,使的线程与线程之间能够独立的访问各自副本.Threadlocal 内部维护一个Map,key为线程的名字,value为对应操作的副本. /** ...
- 简单事件机制Java实现
一个很简单方便的事件处理方法. 使用效果 事件发布者: //定义事件 public static EventTrans<String> AuthFailed = new EventTran ...
- 小谈Scrum敏捷开发流程
一晃眼,有两年没有写博客了,回顾前两年,各种奔波,各种忙碌,也有不少的收获.从今天开始,我要把这些收获都分享在这里. 其实这两年,对我影响最大的是开发流程.总所周知,一个好的开发流程,对于项目的进行, ...