转发.

[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. Kooboo CMS技术文档之一:Kooboo CMS技术背景

    语言平台 依赖注入方案 存储模型 1. 语言平台 Kooboo CMS基于.NET Framework 4.x,.NET Framework 4.x的一些技术特性成为站点开发人员使用Kooboo CM ...

  2. TemplateMethod(模块方法模式)

    /** * 模块模式 * @author TMAC-J * 将一个完整的算法分离,分成不同的模块 * 用于有很多步骤的时候,可能以后这些步骤还会增加,把这些步骤分离 * 将有共性的部分放在抽象类中 * ...

  3. VC中的MFC到底是什么?

    1. 微软基础类库(英语:Microsoft Foundation Classes,简称MFC)是一个微软公司提供的类库(class libraries),以C++类的形式封装了Windows API ...

  4. swift开发新项目总结

    新项目用swift3.0开发,现在基本一个月,来总结一下遇到的问题及解决方案   1,在确定新项目用swift后,第一个考虑的问题是用纯swift呢?还是用swift跟OC混编      考虑到新项目 ...

  5. 【一起学OpenFoam】02 软件准备

    "工欲善其事必先利其器",在利用OpenFoam解决我们的工程问题之前,首先要做的事情是搭建一个OpenFoam运行环境.很遗憾的是,OpenFoam的原生开发系统是Linux,因 ...

  6. 一步步学习javascript基础篇(8):细说事件

    终于学到事件了,不知道为何听到“事件”就有一种莫名的兴奋.可能是之前的那些知识点过于枯燥无味吧,说起事件感觉顿时高大上了.今天我们就来好好分析下这个高大上的东西. 可以说,如果没有事件我们的页面就只能 ...

  7. 【Knockout.js 学习体验之旅】(1)ko初体验

    前言 什么,你现在还在看knockout.js?这货都已经落后主流一千年了!赶紧去学Angular.React啊,再不赶紧的话,他们也要变out了哦.身旁的90后小伙伴,嘴里还塞着山东的狗不理大蒜包, ...

  8. APP开放源码第一弹《纳豆》

    2016年7月2日,这是一个风轻云淡的日子,DeviceOne平台的用户Star将自己经过一段时间研发的产品通过官方的渠道开源出来,这不仅是对自己设计的高度自信.更是想体现一下自己对于DeviceOn ...

  9. HTPC家庭娱乐和XBOX未来发展畅想<另:创业工作机会>

    微软中国在上海举办新闻发布会,正式宣布Xbox One将于9月23日在中国开始销售,定价3699元起.这款早在2001年就发布的电视游戏机终于在经历了14年的等待后,进军中国大陆市场.此次Xbox O ...

  10. 如何在高并发分布式系统中生成全局唯一Id

    月整理出来,有兴趣的园友可以关注下我的博客. 分享原由,最近公司用到,并且在找最合适的方案,希望大家多参与讨论和提出新方案.我和我的小伙伴们也讨论了这个主题,我受益匪浅啊…… 博文示例: 1.     ...