Developing WCF Data Services and OData applications for Oracle Database

Source: Internet
Author: User
Tags oracle developer visual studio 2010

Developing WCF Data Services and OData applications for Oracle Database

This tutorial contains the following sections:

Objective
The time required
Overview
Prerequisite
Create a new Web site project
Create a new ADO Entity Data Model
To create a WCF data service using EDM data
Summarize
Developing WCF Data Services and OData application purposes for Oracle Database

This tutorial shows you how to use Visual Studio to develop a WCF data Services and Open Database Protocol (ODATA) application for Oracle Database.

The time required

About 15 minutes

Overview

Microsoft WCF Data Services supports the creation and use of a WEB data service. To do this, it uses OData to expose data as a resource that can be addressed through URIs, such as a Web site URL. The Entity Data Model (EDM) that is applied to the Microsoft entity Framework can expose data through WCF data Services and OData to make the EDM more widely available.

In this tutorial, you will learn how to expose Oracle database data using WCF data Services and OData through Oracle's Entity Framework support.

First, create a new EDM from HR mode. Next, create a WCF data service that uses OData to expose the EDM through the Web. Finally, run the WEB application and execute a URL query to retrieve the data from the database.

Prerequisite

Before you begin this tutorial, you should:

1.

Install Microsoft Visual Studio 2010 and the. NET Framework 4 or later versions.

2.

Install Oracle Database 10.2 or later, or install Oracle database XE.

3.

Install Oracle 11g Oracle Data Access Components (ODAC) 11.2.0.2.30 or later from OTN. ODAC downloads include the Oracle Developer Tools for Visual Studio and odp.net that will be used in this tutorial.

4.

Install Internet Explorer version 7 or later, or any browser that supports modern WEB protocols.

5.

Unzip the files into the working directory.

Create a new Web site project

1.

Open Visual Studio. Click File. Choose New > Web Site.

2.

Select ASP. NET Web Site and click OK. A new ASP. NET Web Site Project has now been created.

Create a new ADO Entity Data Model


An EDM is required to expose Oracle data through WCF data Services. In this section, you will use the Entity Data model Wizard to create an EDM based on the EMPLOYEES table in HR mode.

1.

In the Solution Explorer , right-click the newly created Web site project. Select Add New Item.

2.

Select the ado Entity Data Model and click Add.

3.

Click Yesin the dialog box.

4.

In the Entity Data Model Wizard, select Generate from Database and click Next.

5.

If you do not have an HR data connection yet, click New Connection. Select an available data source name, such as ORCL. Enter HR as User Name and enter the password. Click OK.

If you already have an HR connection, select the data connection, such as the HR shown on the screen . ORCL. Select Yes, include the sensitive data in the connection string. Click Next.

6.

Select the Oracle table that you want to map to the EDM. Expand the Tables node and select EMPLOYEES. Click Finish.

7.

The model.edmx page is displayed with the newly created EDM.

To create a WCF data service using EDM data

In this section, you will create a WCF data service. The data service is then configured to use the EDM to retrieve EMPLOYEES data from the database. Finally, by modifying the URL to execute the query, the browser is used to retrieve the Oracle data. Use OData to support data access.

1.

Right-click in the Solution Explorer window and select Add New Item.

2.

Select WCF Data Servicein the Online Templates , and then click Add.

3.

Configure the WcfDataService.cs code page to retrieve data and provide access. To retrieve data for Wcfdataservice:D ataservice , you need to replace the </* Todo:put your data source class name here */> with <model.entities>. It is the EDM that you just created.

Cancels the config. Setentitysetaccessrule the comment and replace "Myentityset " with " *". Click Run Application.

4.

The site is open and the Address bar displays the following URL:http://localhost:< port name >/< website Project name >/

5.

In the URL, enter /wcfdataservice.svcafter the name of the site to see which entities are already included.

6.

Make sure that the source reading view for Internet Explorer is disabled before you execute the query through a URL. Otherwise, the browser will return the ATOMPUB encoded document as an XML source instead of displaying the original XML data.

To do this, perform the following steps:

Choose Tools > Internet options

7.

Select the Content tab. Select Settingsfrom the Feeds and Web Slices section.

8.

Uncheck Turn on feed reading view, then click OK.

9.

To perform some query examples by URL, you can open the sample Queries-hr.txtin your working directory. The port number and site project name may differ from your project. Therefore, these query examples can only be used as guidelines and cannot be copied and pasted directly into the browser.

To query the EMPLOYEES entity, you need to add/employees to the URL. The Web site will execute the query as shown below.

10.

To perform a employee_id = 100 query, copy /employees (100M) from Sample queries-hr.txt and paste into the URL. The Web site will execute the query as shown below.

11.

To query the first_name of employee_id = 100, copy /employees (100M)/first_name from Sample queries-hr.txt and paste into the URL. The Web site will execute the query as shown below.

12.

To query the total number of rows, copy the /employees/$count from Sample queries-hr.txt and paste it into the URL. The Web site will execute the query as shown below.

13.

To query the top two employees, copy/employees from Sample queries-hr.txt . $top =2 and paste into the URL. The Web site will execute the query as shown below.

14.

To query last_name = King's EMPLOYEES, copy/employees from Sample queries-hr.txt ? $filter =last_name eq ' KING ' and paste to the URL. The Web site will execute the query as shown below.

15.

To query the EMPLOYEES of more than 10000 wages per payroll cycle, copy EMPLOYEES from Sample queries-hr.txt ? $filter =salary GT 10000 and paste to URL In The Web site will execute the query as shown below.

Summarize

In this tutorial, you learned how to:

    • Create a new Web site project in Visual Studio.
    • Create a new ADO Entity Data Project from Oracle mode.
    • Use the EDM data to create an Oracle WCF data service and use OData to execute various queries by modifying the URL.

      • Course Design staff: Anupama Mandya
      • Other personnel: Alex Keh

Developing WCF Data Services and OData applications for Oracle Database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.