OData provide two tools to generate client proxy file for an OData Service.

The following part will mainly focus on how to use the OData Connected Service to generate client proxy file.

Install OData Connected Service Extension

You can install this extension by this link from vs gallery. Or, you can install it in Visual Studio 2015.

In Visual Studio, Click Tools > Extensions and Updates.

Expand Online > Visual Studio Gallery > Tools > Connected Service, and select the OData Connected Service extension.

Click Download.

Then it will pop up a VSIX Installer window, Click Install.

Click Close once the installation finishes.

You need to restart the visual studio in order for the installation to take effect.

Generate Client Proxy#

Create a new project

Create your project. Here, we take “Console Application” project as an example.

Start Visual Studio and from the File menu, select New and then Project.

In the Templates pane, select Installed > Templates, expand the Visual C# > Windows > Classic Desktop and select Console Application. Name the Project “TrippinApp” and click OK.

Generate client proxy for an OData service

In the Solution Explorer pane, right click the “TrippinApp” project and select Add and then Connected Service.

In the Add Connected Service dialog, select OData and then click Configure.

In the Configure endpoint dialog, input the service name and the OData service endpoint, then click Next button.

In the Settings dialog, enter the file name(without extension) of the proxy file and click Finish.

In the Settings dialog, You also can configure some other settings by click AdvancedSettings link. Then you can set the related code generation settings.

Once you finished all those settings, click Finish. This tool will begin to install the related NuGet packages and generate the client proxy file into your project.

Consume the OData service

Now, the developer can write client code to consume the OData Service.

using System;
using Microsoft.OData.SampleService.Models.TripPin;

namespace TrippinApp
{
    class Program
    {
        static void Main(string[] args)
        {
            DefaultContainer dsc = new DefaultContainer(
                new Uri("http://services.odata.org/V4/(S(fgov00tcpdbmkztpexfg24id))/TrippinServiceRW/"));
            var me = dsc.Me.GetValue();
            Console.WriteLine(me.UserName);
        }
    }
}

Summary

Now you have the OData Connected Service at your disposal to generate your client proxy for any OData service. To leave us feedback, please open github issues at OData Lab GitHub.