Introduction to WCF Data service and ODATA Creating WCF Data Service Consuming WCF Data Service WCF Data Service, Project Astoria, OData and ADO.Net Data Service are same thing. What is ODATA?• ODATA is HTTP or web protocol to quering or manipulating data! • ODA T A use s HTTP" #OS$ or A TO%! • ODA T A can be implemented t&roug& anplat'orm supports" HTTP" (%) or #SO$! • ODATA can e*pose data+in'ormation 'rom relational database" File sstems" Web sites" services etc! • ODATA speci,cation available under %icroso't-s Open Speci,cation Promise .OSP/ so t&ird parties" including open source pro0ects" can build Open Data Protocol clients and services! What is WCF Data Service?• WCF Data service 'ramewor1 provides an API t&at allows data to be created and consumed over HTTP using 23ST'ul service! • WCF Data service supports all database operations using 42I! • WCF Data service can e*pose an entitmodel via an 42I! • WCF Data service is 23ST'ul service to support C24D operations on database! • WCF Data service could be consumed bantpe o' client li1e Windows" Silver)ig&t" Web" A#A( and console!
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
8/10/2019 Introduction to WCF Data Service and ODATA
Creating WCF Data ServiceConsuming WCF Data Service
WCF Data Service, Project Astoria, OData and ADO.Net Data Service are samething.
What is ODATA?
• ODATA is HTTP or web protocol to quer ing or manipulating data!• ODATA uses HTTP" #OS$ or ATO%!
• ODATA can be implemented t&roug& an plat'orm supports" HTTP" (%) or #SO$!
• ODATA can e*pose data+in'ormation 'rom relational database" File s stems" Websites" services etc!
• ODATA speci,cation available under %icroso't-s Open Speci,cation Promise .OSP/so t&ird parties" including open source pro0ects" can build Open Data Protocolclients and services!
What is WCF Data Service? • WCF Data service 'ramewor1 provides an API t&at allows data to be created and
consumed over HTTP using 23ST'ul service!• WCF Data service supports all database operations using 42I!
• WCF Data service can e*pose an entit model via an 42I!
• WCF Data service is 23ST'ul service to support C24D operations on database!
• WCF Data service could be consumed b an t pe o' client li1e Windows"Silver)ig&t" Web" A#A( and console!
In above connection string StudentD;3ntities is name o' t&e connection string! I'we want" we can c&ange t&is connection string as per our requirement! I' ourrequired data base is not listed in drop down t&en" ou can create a new dataconnection! To create new data connection clic1 on $ew Connection!
8/10/2019 Introduction to WCF Data Service and ODATA
<ou can give t&e data base server name and press re'res&! A'ter pressing 2e'res&"ou can c&oose t&e data base 'rom t&e drop down! A'ter selecting t&e data baseclic1 on Test Connection to test connection establis&ed success'ull or not=
>! Select tables" views and stored procedure 'rom data base ou want to ma1e ast&e part o' our data model! Since we are &aving onl one table so we areselecting one table!
8/10/2019 Introduction to WCF Data Service and ODATA
I' ou want ou can c&ange name o' t&e data model! ; de'ault it is name o' t&edata base appended b t&e term model! Clic1 on Finis& button to complete and
create t&e data model!?! $ow we can see t&at StudentData%odel!edm* &as been created in t&e designer!
Since t&ere is onl one table" so t&ere is onl one table model at design sur'ace!
8/10/2019 Introduction to WCF Data Service and ODATA
$ow we &ave created t&e data model w&ic& can be e*posed as WCF Data Service! $ow ou can see in solution e*plorer" ou &ave Student%odel!edm* andStdent%odel!Designer!cs ,les!
Ste" Creating WCF Data Service 5! 2ig&t clic1 on Web Application pro0ect and add a new item!7! Select WCF Data Service 'rom Web tab! 9ive an meaning'ul name! I am leaving
t&e de'ault name &ere!
8! A'ter adding t&e WCF Data Service" we can see a service ,le wit& e*tension !svc&as been added to t&e solution e*plorer! W&en we clic1 on !svc!cs ,le" we can see
t&e code generated 'or us!
8/10/2019 Introduction to WCF Data Service and ODATA
@er ,rst we need to put data source name! To do so uncomment t&e ,rstcommented line and put t&e data source name! In our case name o' t&e model"w&ic& we created in 7nd step is t&e data source! Our data source name isStudentD;3ntities
$ow we need to set access rules 'or entit or entit set! Since we &ave onl onetable" so eit&er we can give name o' t&e table e*plicitl or i' we want to set t&esame access rule 'or all t&e table in t&e data model or data source we could put !
So we are setting t&e access rule t&at" on t&e entit in data source per'orm all t&eoperations!
Ste" / %)n the WCF Data Service
#ust press F> to run t&e WCF Data Service! Data Service will be &osted in t&e de'aultASP!$et server called Cassini!
On running ou can see" one table is listed! T&at table is Student
T&e above is t&e data in ATO% message 'ormat!
Note B I' our browser is not s&owing t&e e*pected result" ma1e sure Feed reading o'browser is o ! To do 'rom menu o' I3 and select tool and t&en Internet Option t&enContent
8/10/2019 Introduction to WCF Data Service and ODATA
T&is will permit all write access on Student entit set!
Creating a client to cons)me WCF Data Service
Ste" +
Add a new pro0ect in t&e same solution o' t pe console application!
Ste" -
Add t&e service re'erence o' WCF Data Service! To add rig&t clic1 on t&e console pro0ectand add a service re'erence! Since WCF Data Service and client pro0ect in t&e samesolution " clic1 on Discover to discover t&e service in t&e solution!
8/10/2019 Introduction to WCF Data Service and ODATA
$eed to create instance o' DataConte*t and StudentD;3ntities! T&ese two classes ta1eas parameter in t&eir constructor! Parameter is base 42I o' t&e WCF Data Service!
%etrieving all the records o$ ta(le St)dents
Adding one record in the ta(le St)dent
&"dating a record in the ta(le St)dent
8/10/2019 Introduction to WCF Data Service and ODATA