DEV Community

Cover image for How to generate C# or Visual Basic client code for OData protocol versions 1.0–4.0
Chebotov Nickolay
Chebotov Nickolay

Posted on

How to generate C# or Visual Basic client code for OData protocol versions 1.0–4.0

Alt Text

This How-To describes how to generate C# or Visual Basic client code for OData protocol versions 1.0–4.0 with Unchase OData Connected Service to Visual Studio 2017/2019 projects.

The Unchase OData Connected Service is a Visual Studio 2017/2019 extension to generate C# (Visual Basic) client code for OData web services. Simply put, it is like kind old Add Service Reference for WCF or Add Web Reference for WSDL, but for OData protocol versions 1.0–4.0.

Follow 4 steps below to achieve this:

Alt Text

Step 1. Install the Connected Service

Launch the installed Visual Studio 2017/2019. Open the menu to manage Visual Studio extensions:

  • For Visual Studio 2017: Tools -> Extensions and Updates...

Alt Text

  • For Visual Studio 2019: Extensions -> Manage Extensions

Alt Text

Choose Online -> Visual Studio Marketplace tab. In search field type unchase, then install Unchase OData Connected Service (just click Download button):

Alt Text

After all, restart the Visual Studio to install the Connected Service.

Step 2. Open the Connected Service wizard for Visual Studio project

Open the Visual Studio solution with project to generate client code in. In Solution Explorer make right-click on Connected Services or Dependencies item in the project for which you need to generate client code, and click on Add Connected Service:

Alt Text

Alt Text

Then choose Unchase OData Connected Service to show the Connected Service wizard:

Alt Text

Alt Text

Step 3. Configure OData metadata endpoint

In the first page of the wizard you need to configure some necessary options:

  • Generating Language - C# or Visual Basic client code generation option;

  • Service name - the name of the folder (after generation) in Connected Service directory in the project (by default, if field is empty - OData Service);

  • OData metadata URI (path) - the metadata endpoint URI (URL or local file).

Alt Text

After setting the necessary options, you can immediately start generating the code files by clicking the Finish button. In this case, there will choose default code generation options.

If you find a bug in the Connected Service, you can use the "Report a bug" button.


There are a few optional options you can specify before start generation process:

  • Load from 'Connected Service.json' button - allows load client code generation parameters from json-file generated by Unchase OData Connected Service or OData Connected Service by Microsoft;

  • Open generated files on complete in IDE checkbox - allows automatically open the generated files in IDE in generation process;

  • Accept all untrusted certificates checkbox - allows to accept all untrusted certificates when connecting to the services;

  • If you need to set network credentials for connecting to the endpoint (metadata file), you should specify options in the Network Credentials section. If your network used Proxy, you should specify options in the Web Proxy section:

Alt Text

Step 4 (Optional). Configure code generation options

If you want to specify some options for generating code, just need to go to generation settings tab(s):

  • Common OData protocol versions 1.0–4.0 Advanced Settings wizard page settings:

Alt Text

There you can specify generated client code file name.

  • OData protocol versions 1.0–3.0 Advanced Settings wizard page setting in AdvancedSettings link:

Alt Text

If you check Select OData methods from FunctionImports (V3) or OperationImports (V4), the wizard page (tab) named Operation Imports Settings will be added where you can select the necessary methods that will be added after generation:

Alt Text

  • OData protocol version 4.0 Advanced Settings wizard page setting in AdvancedSettings link:

Alt Text


Enjoy programming with Unchase!

Top comments (0)