How to: Manually Generate Client Data Service Classes (WCF Data Services)

WCF Data Services integrates with Visual Studio to enable you to automatically generate client data service classes when you use the Add Service Reference dialog box to add a reference to a data service in a Visual Studio project. For more information, see How to: Add a Data Service Reference (WCF Data Services). You can also manually generate the same client data service classes by using the code-generation tool, DataSvcUtil.exe. This tool, which is included with WCF Data Services, generates .NET Framework classes from the data service definition. It can also be used to generate data service classes from the conceptual model (.csdl) file and from the .edmx file that represents an Entity Framework model in a Visual Studio project.

Tip

When you need to generate client data service classes from an authenticated OData service, first download the .edmx file from the data service in a Web browser, supplying the required credentials. Then, run the DataSvcUtil.exe tool against the locally saved .edmx file.

The example in this topic creates client data service classes based on the Northwind sample data service. This service is also created when you complete the WCF Data Services quickstart. Some examples in this topic require the conceptual model file for the Northwind model. For more information, see How to: Use EdmGen.exe to Generate the Model and Mapping Files. Some examples in this topic require the .edmx file for the Northwind model. For more information, see .edmx File Overview (Entity Framework).

Note

In the following examples, you must use the %ProgramFiles(x86)% environment variable when you run the command on a 64-bit computer.

To generate C# classes based on the service URI

  • At the command prompt, execute the following command without line breaks:

    "%ProgramFiles%\Microsoft WCF Data Services\5.0\bin\.NETFramework\DataSvcUtil.exe" /dataservicecollection /version:3.0 /language:CSharp /out:Northwind.cs /uri:http://services.odata.org/Northwind/Northwind.svc/
    

To generate Visual Basic classes based on the service URI

  • At the command prompt, execute the following command without line breaks:

    "%ProgramFiles%\Microsoft WCF Data Services\5.0\bin\.NETFramework\DataSvcUtil.exe" /dataservicecollection /version:3.0 /language:VB /out:Northwind.vb /uri:http://services.odata.org/Northwind/Northwind.svc/
    

To generate C# classes based on the .edmx file

  • At the command prompt, execute the following command without line breaks:

    "%ProgramFiles%\Microsoft WCF Data Services\5.0\bin\.NETFramework\datasvcutil.exe" /dataservicecollection /version:3.0 /language:CSharp /in:Northwind.edmx /out:c:\northwind.cs 
    

To generate Visual Basic classes based on the .edmx file

  • At the command prompt, execute the following command without line breaks:

    "%ProgramFiles%\Microsoft WCF Data Services\5.0\bin\.NETFramework\datasvcutil.exe" /dataservicecollection /version:3.0 /language:VB /in:Northwind.edmx /out:c:\northwind.vb 
    

To generate C# classes based on the conceptual model file (CSDL)

  • At the command prompt, execute the following command without line breaks:

    "%ProgramFiles%\Microsoft WCF Data Services\5.0\bin\.NETFramework\datasvcutil.exe" /dataservicecollection /version:3.0 /language:CSharp /in:Northwind.csdl /out:Northwind.cs
    

To generate Visual Basic classes based on the conceptual model file (CSDL)

  • At the command prompt, execute the following command without line breaks:

    "%ProgramFiles%\Microsoft WCF Data Services\5.0\bin\.NETFramework\datasvcutil.exe" /dataservicecollection /version:3.0 /language:VB /in:Northwind.csdl /out:Northwind.vb
    

See Also

Tasks

How to: Add a Data Service Reference (WCF Data Services)

Reference

WCF Data Service Client Utility (DataSvcUtil.exe)

Concepts

Generating the Client Data Service Classes (WCF Data Services)