I want to create WCF oData Service (RESTful Service) using U2 Toolkit for .NET and U2 Database. Then I want to consume oData Service in any .NET Client Application.
相关问题
- Design RESTful service with multiple ids
- Axios OPTIONS instead of POST Request. Express Res
- Plain (non-HTML) error pages in REST api
- Laravel 5.1 MethodNotAllowedHttpException on store
- Can I parameterize labels and properties on CREATE
相关文章
- odata怎么开启括号查询
- Got ActiveRecord::AssociationTypeMismatch on model
- Multiple parameters in AngularJS $resource GET
- Global Exception Handling in Jersey & Spring?
- REST search interface and the idempotency of GET
- Getting error detail from WCF REST
- Send a GET request with a body in JavaScript (XMLH
- GuzzleHttp Hangs When Using Localhost
Please see my answer below:
Overview
WCF Data Services exposes entity data as a data service. This entity data can be created from U2 Database using U2 Toolkit for .NET. This topic shows you how to create an Entity Framework-based data model in a Visual Studio Web application that is based on an existing database and use this data model to create a new WCF oData service (RESTful Service). You can consume WCF oData Service in different .NET application such as:
Installation
You need to install U2 toolkit for .NET v 1.2.0. It contains U2 ADO.NET Provider and U2 Database Add-ins for Visual Studio
Create Entity Data Model with existing U2 Account
We will use U2 UniVerse ‘s sample database called “HS.SALES”. 1. Create ASP.NET Web Application called ‘U2_WCF_oData_WebApplication’
Type the model name and then click Add.
In the Choose Model Contents dialog box, select Generate from database. Then click Next.
Create WCF oData Service (RESTful Service) using the new data model (Customer Model)
public class U2_Customer_WcfDataService : DataService< /* TODO: put your data source class name here */ >
In the code for the data service, enable authorized clients to access the entity sets that the data service exposes. For more information, see Creating the Data Service.
// config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
To test the ‘U2_Customer_WcfDataService.svc ‘ data service by using a Web browser, press Visual Studio ->Debug->StartWithoutDebugging
Consume WCF oData Service (RESTful Service)
2. Add Service Reference
Open ‘MainWindow.xaml.cs’ file. Add this line ( yours uri will be different).
private Uri svcUri = new Uri("http://localhost:38346/U2_Customer_WcfDataService.svc/");
Add this line.
U2_WCF_oData_ServiceReference.CustomerEntities ctx = new U2_WCF_oData_ServiceReference.CustomerEntities(svcUri);
Add this line.
cUSTOMERsViewSource.Source = ctx.CUSTOMERs.ToList();
Your competed code will look as below. public partial class MainWindow : Window { private Uri svcUri = new Uri("http://localhost:38346/U2_Customer_WcfDataService.svc/");
}
Set WPF application as ‘Startup Project’. Run WPF Application.