转发.

[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. [C#] C# 知识回顾 - 学会使用异常

    学会使用异常 在 C# 中,程序中在运行时出现的错误,会不断在程序中进行传播,这种机制称为“异常”. 异常通常由错误的代码引发,并由能够更正错误的代码进行 catch. 异常可由 .NET 的 CLR ...

  2. zookeeper源码分析之六session机制

    zookeeper中session意味着一个物理连接,客户端连接服务器成功之后,会发送一个连接型请求,此时就会有session 产生. session由sessionTracker产生的,sessio ...

  3. 说一说python的牛比与不爽

    本人写了10年php了.今年开始改写python了.不是说php有什么不好,php在自己的势力范围内还是很牛比的.只是我已经不能满足于php那两亩地了. 习惯了脚本,所以很自然就过度到python了. ...

  4. 深入理解css3中nth-child和 nth-of-type的区别

    在css3中有两个新的选择器可以选择父元素下对应的子元素,一个是:nth-child 另一个是:nth-of-type. 但是它们到底有什么区别呢? 其实区别很简单::nth-of-type为什么要叫 ...

  5. 【干货分享】流程DEMO-出差申请单

    流程名: 出差申请  业务描述: 员工出差前发起流程申请,流程发起时,会检查预算,如果预算不够,将不允许发起费用申请,如果预算够用,将发起流程,同时占用相应金额的预算,但撤销流程会释放相应金额的预算. ...

  6. Android—应用程序开机自启

    android开机时候会发送开机广播,我们想要收到广播知道手机开机,才能启动我们的应用程序. 首先要在配置文件中添加相应权限: <uses-permission android:name=&qu ...

  7. SMBus set up a 2-byte EEPROM address for read/write

    Sequencer Engine spec: http://www.analog.com/media/en/technical-documentation/data-sheets/ADM1260.pd ...

  8. Centos、Ubuntu 安装 Mono、Jexus

    Mono是.NET的跨平台实现 在众多关于语言的争论中,.NET一直被以不能跨平台而诟病,Mono改变了这一现状. 有人当心Mono会涉及版权啥的问题.高深的偶不懂,不过我觉得Unity3D都能用,为 ...

  9. 【Java并发编程实战】-----“J.U.C”:CAS操作

    CAS,即Compare and Swap,中文翻译为"比较并交换". 对于JUC包中,CAS理论是实现整个java并发包的基石.从整体来看,concurrent包的实现示意图如下 ...

  10. ValueInjecter----最好用的OOM(以微信消息转对象举例)

    使用数据实体的好处我这里就不多说了,但大家享受这些好处的时候,难免也对那些琐碎的赋值代码感到厌烦,基于此,我认为掌握一个oom的使用,还是很有必要的. 这种类型的工具有很多,比如automapper, ...