Basic Ado.net Data Services 5 minutes job Part -I

 1. What is Ado.net Data Services ? 

 

http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx

 

 Ado.Net Services formaly known as “Astoria“. It’s a facility that is used as a web services over net just like simple http with well known data format like jason or XML.

It’s a feature that allow user to mainuplate, traverse data through simple URIs. This allow easy access of data. The concept comes from general programming concept reffered as REST.It is avalilable with Vs 2008 + SP1.According to me I found only one and most important point that it is easily navigate through url.

Which is best feature.

2. What  it requires to run it ?

 

For this you have to install vs2008’s service pack 1 which is easily available at

 

 

 

 

3) Basic  Example for understanding :-

 

System.Data.Services

Here I am going to explain an example just follow the same way for initital starting. Just follow below step.

Step 1:-

Add new web project

Step 2:- Now add a new item “Ado.net Data Service” as shown in below fig when you add it. It adds a new item in your project just like I added “RajatDataService.svc

 

AddAdoNetService

 

By default you get shared method which is initializeService

Step3:- Add new item Ado.net Entity model as shown in below fig.

 

addmodelentity

 

Once you add it then you will get screen like below fig it has edmx extention.

 

entitymodel

Before going further I just explain you in breif edmxAdo.net entity model ” is just like Your linq mapper with extended functionality I will explain this later on in my new

Post. But for current point of time just think as ORM.

Step4 :- Once you done with this you have to do following code in your DataService.svc.vb file’s default shared method as we said in step 2

 

Imports 

 

 

Imports System.Linq

Imports System.ServiceModel.Web 

Public Class RajatAdoNetService 

 

 

 

 

    Inherits DataService(Of MedicalProEntities)

 

 

 

 

‘The medical proEntries is your model entry class

 

 ‘ This method is called only once to initialize service-wide policies.

 

 Public Shared Sub InitializeService(ByVal config As IDataServiceConfiguration) 

 

‘ TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.

 

 

 config.SetEntitySetAccessRule(“*” , EntitySetRights.AllRead) 

 

‘ above line is use for access rules for entities in model

 

 

 

 ‘if you want to access particular entity (table) from database then just give entity name at the place of * like below

 

 ‘ config.setEntitySetAccessRules(“tblProduct”,entitySetRight.allRead)

 

 ‘ The second option is for mainly giving rights like , read ,write,delete etc on entity set

 config.SetServiceOperationAccessRule(“*”, ServiceOperationRights.All) 

 

 

 

‘ The above line is service opration accessRules in this again just put * int first parameter, and all in second parameter

 End Sub

End  Class

 

 

Once you done with above code just set your .Svc page as set as start page and run the application. And you will be supprise you will get below screen

 

http://localhost:3120/RajatAdoNetService.svc/)

 

svc
You will find in the above fig that all the tables are with in xml format. URL (
Now suppouse you want to access particular table database then you have to write fllowing url in addressbar

 

http://localhost:3120/RajatAdoNetService.svc/tblBank

 

 
Then if you are not able to view data and get bleow screen

 

http://localhost:3120/RajatAdoNetService.svc/tblProduct

 feederror

Then go to Internet explore option Tools –> Internet options –> Content tab ‘s Feed setting option and uncheck all the checkbox then

Refresh you will get fllowing screen

bankdata

Step 6:-

Simillarly you can access any entity in entity model or we can say any table from url.

 

Suppose I want to access product table then I have to write

 

 

 

I this way we can get table with data in xml format as shown above.

 

 

http://localhost:3120/RajatAdoNetService.svc/tblBank(36)

Where 36 is identity column value.

 

http://localhost:3120/RajatAdoNetService.svc/tblBank(36)/strBank

 

Step 8: if you want to access particular id’s column field’s value then you have to write column name also in url suppose I want tblbank’s strbankCode column value where id = 36 then I have to write below url 
As shown below

 

 

bankidparticulardata

 

I know this is not enough for your hunger even my too so don’t worry i will come up with more suitable example and live demo soon  here I hope you people got basic understanding. I will come up with latest example and more description in next chapters

Till then enjoy the code.

Keep Shining & Keep  Pushing  , Keep programming

Thanks

Rajat Jaiswal

 

 

Step 7:- if you want to access particular id data then you have to write following url

 

 

Advertisements

2 thoughts on “Basic Ado.net Data Services 5 minutes job Part -I

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s