共用方式為


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

Important

WCF Data Services has been deprecated and will no longer be available for download from the Microsoft Download Center. WCF Data Services supported earlier versions of the Microsoft OData (V1-V3) protocol only and has not been under active development. OData V1-V3 has been superseded by OData V4, which is an industry standard published by OASIS and ratified by ISO. OData V4 is supported through the OData V4 compliant core libraries available at Microsoft.OData.Core. Support documentation is available at OData.Net, and the OData V4 service libraries are available at Microsoft.AspNetCore.OData.

RESTier is the successor to WCF Data Services. RESTier helps you bootstrap a standardized, queryable, HTTP-based REST interface in minutes. Like WCF Data Services before it, Restier provides simple and straightforward ways to shape queries and intercept submissions before and after they hit the database. And like Web API + OData, you still have the flexibility to add your own custom queries and actions with techniques you're already familiar with.

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. 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.

The example in this topic creates client data service classes based on the Northwind sample data service. This service is 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.

To generate C# classes that support data binding

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

    "%windir%\Microsoft.NET\Framework\v3.5\DataSvcUtil.exe" /dataservicecollection /version:2.0 /language:CSharp /out:Northwind.cs /uri:http://localhost:12345/Northwind.svc
    

    Note

    You must replace the value supplied to the /uri: parameter with the URI of your instance of the Northwind sample data service.

To generate Visual Basic classes that support data binding

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

    "%windir%\Microsoft.NET\Framework\v3.5\DataSvcUtil.exe" /dataservicecollection /version:2.0 /language:VB /out:Northwind.vb /uri:http://localhost:12345/Northwind.svc
    

    Note

    You must replace value supplied to the /uri: parameter with the URI of your instance of the Northwind sample data service.

To generate C# classes based on the service URI

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

    "%windir%\Microsoft.NET\Framework\v3.5\DataSvcUtil.exe" /language:CSharp /out:northwind.cs /uri:http://localhost:12345/Northwind.svc
    

    Note

    You must replace the value supplied to the /uri: parameter with the URI of your instance of the Northwind sample data service.

To generate Visual Basic classes based on the service URI

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

    "%windir%\Microsoft.NET\Framework\v3.5\datasvcutil.exe" /language:VB /out:Northwind.vb /uri:http://localhost:12345/Northwind.svc
    

    Note

    You must replace value supplied to the /uri: parameter with the URI of your instance of the Northwind sample data service.

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

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

    "%windir%\Microsoft.NET\Framework\v3.5\datasvcutil.exe" /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:

    "%windir%\Microsoft.NET\Framework\v3.5\datasvcutil.exe" /language:VB /in:Northwind.csdl /out:Northwind.vb
    

To generate C# classes based on the .edmx file

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

    "%windir%\Microsoft.NET\Framework\v3.5\datasvcutil.exe" /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:

    "%windir%\Microsoft.NET\Framework\v3.5\datasvcutil.exe" /language:VB /in:Northwind.edmx /out:c:\northwind.vb
    

See also