联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2018-10-01 09:36

COMSCI 335 / 2018 / v1 Page 1 of 8 radu&james

Assignment #4R: OData REST services

Introduction

This assignment requires you to create two OData REST services that accept GET requests, in order

to retrieve data from two XML “table” documents: XOrders.xml and XCustomers.xml, in

ATOM+XML or JSON formats.

These XML documents are trimmed (and slightly modified) versions of the similarly named tables –

Orders and Customers – from the public and well-known Northwind SQL database sample.

The service must be written in two versions, written (1) in C# and (2) in F#, starting with the

provided skeletons. These two projects will be compiled with their command-line compliers, CSC

and FSC, respectively, via given batch files. The services will tested by running IISExpress via another

given batch file (we’ll typically run this on port 8181, which is available in the labs). The marking will

be performed by scripts, so exact matches are essential.

Server data

Our XML documents are not schema based. Therefore, let’s also have a look the original SQL types,

as Linqpad sees these. This will allow us to properly identify the types.

Note the several Orders properties that are nullable (?) – We keep three of these (see below)!

Note the following primary keys: OrderID for Orders and CustomerID for Customers. Note also the

foreign key CustomerID in Orders. Together, these define the following “duck’s paw” one-to-many

and many-to-one relationships:

o Customer: from Orders to Customers

o Orders: from Customers to Orders

COMSCI 335 / 2018 / v1 Page 2 of 8 radu&james

Our XML documents keep only part of the actual SQL columns

o XOrders keeps, in order: OrderID, CustomerID, OrderDate , ShippedDate, Freight ,

ShipName, ShipCity, and ShipCountry – also EmployeeID, but this will be ignored.

o XCustomers keeps, in order: CustomerID, CompanyName, and ContactName.

o The “ducks’ paw” relationships must be rebuilt by the program.

Here follow the first few lines of each of our XML documents:

XCategories

<Customers>

<Customer>

<CustomerID>ALFKI</CustomerID>

<CompanyName>Alfreds Futterkiste</CompanyName>

<ContactName>Maria Anders</ContactName>

</Customer>

>

XOrders

<Orders>

<Order>

<OrderID>10248</OrderID>

<CustomerID>VINET</CustomerID>

<EmployeeID>5</EmployeeID> <!—ignore this -->

<OrderDate>1996-07-04T00:00:00</OrderDate>

<ShippedDate>1996-07-16T00:00:00</ShippedDate>

<Freight>32.3800</Freight>

<ShipName>Vins et alcools Chevalier</ShipName>

<ShipCity>Reims</ShipCity>

<ShipCountry>France</ShipCountry>

</Order>

>

The three nullable properties may appear in three different ways, e.g.:

<Freight />

<Freight> </Freight>

<!-- <Freight>32.3800</Freight> -->

COMSCI 335 / 2018 / v1 Page 3 of 8 radu&james

Sample GET URL queries and expected results for C# (for F# replace A4CS => A4FS); slightly

reformatted (added readability spaces), and assuming the service is listening on port 8081.

odata_xml_0

http://localhost:8181/A4CS.svc/?$format=json

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata","value":[

{"name":"Customers","url":"Customers"},

{"name":"Orders","url":"Orders"}]}

odata_xml_1

http://localhost:8181/A4CS.svc/Orders()?$format=json&$top=0&$inlinecount=allpages

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Orders","odata.count":"830",

"value":[]}

odata_xml_2

http://localhost:8181/A4CS.svc/Customers()?$format=json&$orderby=CustomerID&$top=3&$select

=CustomerID,ContactName,CompanyName

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Customers&

$select=CustomerID,ContactName,CompanyName","value":[

{"CustomerID":"ALFKI","CompanyName":"Alfreds Futterkiste",

"ContactName":"Maria Anders"},

{"CustomerID":"ANATR","CompanyName":"Ana Trujillo Emparedados y helados",

"ContactName":"Ana Trujillo"},

{"CustomerID":"ANTON","CompanyName":"Antonio Moreno Taquer\u00eda",

"ContactName":"Antonio Moreno"}]}

odata_xml_3

http://localhost:8181/A4CS.svc/Orders()?$format=json&$orderby=OrderID

desc&$top=3&$select=OrderID,CustomerID,ShipName,ShipCity,ShipCountry

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Orders&

$select=OrderID,CustomerID,ShipName,ShipCity,ShipCountry","value":[

{"OrderID":11077,"CustomerID":"RATTC","ShipName":"Rattlesnake Canyon Grocery",

"ShipCity":"Albuquerque","ShipCountry":"USA"},

{"OrderID":11076,"CustomerID":"BONAP","ShipName":"Bon app'",

"ShipCity":"Marseille","ShipCountry":"France"},

{"OrderID":11075,"CustomerID":"RICSU","ShipName":"Richter Supermarkt",

"ShipCity":"Gen\u00e8ve","ShipCountry":"Switzerland"}]}

COMSCI 335 / 2018 / v1 Page 4 of 8 radu&james

odata_xml_4

http://localhost:8181/A4CS.svc/Orders()?$format=json&$orderby=OrderID&$filter=OrderDate eq

null&$expand=Customer&$select=OrderID,CustomerID,OrderDate,ShippedDate,Freight

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Orders&

$select=OrderID,CustomerID,OrderDate,ShippedDate,Freight","value":[

{"OrderID":10249,"CustomerID":"TOMSP","OrderDate":null,

"ShippedDate":"1996-07-10T00:00:00","Freight":"11.6100"},

{"OrderID":10250,"CustomerID":"HANAR","OrderDate":null,

"ShippedDate":"1996-07-12T00:00:00","Freight":"65.8300"}]}

odata_xml_5

http://localhost:8181/A4CS.svc/Orders()?$format=json&$orderby=OrderID&$filter=ShippedDate eq

null&$expand=Customer&$select=OrderID,CustomerID,OrderDate,ShippedDate,Freight

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Orders&

$select=OrderID,CustomerID,OrderDate,ShippedDate,Freight","value":[

{"OrderID":11008,"CustomerID":"ERNSH","OrderDate":"1998-04-08T00:00:00",

"ShippedDate":null,"Freight":"79.4600"},

{"OrderID":11009,"CustomerID":"GODOS","OrderDate":"1998-04-08T00:00:00",

"ShippedDate":null,"Freight":"59.1100"},

{"OrderID":11010,"CustomerID":"REGGC","OrderDate":"1998-04-09T00:00:00",

"ShippedDate":null,"Freight":"28.7100"},

{"OrderID":11019,"CustomerID":"RANCH","OrderDate":"1998-04-13T00:00:00",

"ShippedDate":null,"Freight":"3.1700"},

{"OrderID":11039,"CustomerID":"LINOD","OrderDate":"1998-04-21T00:00:00",

"ShippedDate":null,"Freight":"65.0000"},

{"OrderID":11040,"CustomerID":"GREAL","OrderDate":"1998-04-

22T00:00:00","ShippedDate":null,"Freight":"18.8400"},

{"OrderID":11045,"CustomerID":"BOTTM","OrderDate":"1998-04-23T00:00:00",

"ShippedDate":null,"Freight":"70.5800"},

{"OrderID":11051,"CustomerID":"LAMAI","OrderDate":"1998-04-27T00:00:00",

"ShippedDate":null,"Freight":"2.7900"},

{"OrderID":11054,"CustomerID":"CACTU","OrderDate":"1998-04-28T00:00:00",

"ShippedDate":null,"Freight":"0.3300"},

{"OrderID":11058,"CustomerID":"BLAUS","OrderDate":"1998-04-29T00:00:00",

"ShippedDate":null,"Freight":"31.1400"},

{"OrderID":11059,"CustomerID":"RICAR","OrderDate":"1998-04-29T00:00:00",

"ShippedDate":null,"Freight":"85.8000"},

{"OrderID":11061,"CustomerID":"GREAL","OrderDate":"1998-04-30T00:00:00",

"ShippedDate":null,"Freight":"14.0100"},

COMSCI 335 / 2018 / v1 Page 5 of 8 radu&james

{"OrderID":11062,"CustomerID":"REGGC","OrderDate":"1998-04-30T00:00:00",

"ShippedDate":null,"Freight":"29.9300"},

{"OrderID":11065,"CustomerID":"LILAS","OrderDate":"1998-05-01T00:00:00",

"ShippedDate":null,"Freight":"12.9100"},

{"OrderID":11068,"CustomerID":"QUEEN","OrderDate":"1998-05-04T00:00:00",

"ShippedDate":null,"Freight":"81.7500"},

{"OrderID":11070,"CustomerID":"LEHMS","OrderDate":"1998-05-05T00:00:00",

"ShippedDate":null,"Freight":"136.0000"},

{"OrderID":11071,"CustomerID":"LILAS","OrderDate":"1998-05-05T00:00:00",

"ShippedDate":null,"Freight":"0.9300"},

{"OrderID":11072,"CustomerID":"ERNSH","OrderDate":"1998-05-05T00:00:00",

"ShippedDate":null,"Freight":"258.6400"},

{"OrderID":11073,"CustomerID":"PERIC","OrderDate":"1998-05-05T00:00:00",

"ShippedDate":null,"Freight":"24.9500"},

{"OrderID":11074,"CustomerID":"SIMOB","OrderDate":"1998-05-06T00:00:00",

"ShippedDate":null,"Freight":"18.4400"},

{"OrderID":11075,"CustomerID":"RICSU","OrderDate":"1998-05-06T00:00:00",

"ShippedDate":null,"Freight":null},

{"OrderID":11076,"CustomerID":"BONAP","OrderDate":"1998-05-06T00:00:00",

"ShippedDate":null,"Freight":null},

{"OrderID":11077,"CustomerID":"RATTC","OrderDate":"1998-05-06T00:00:00",

"ShippedDate":null,"Freight":null}]}

odata_xml_6

http://localhost:8181/A4CS.svc/Orders()?$format=json&$orderby=OrderID&$filter=Freight eq

null&$expand=Customer&$select=OrderID,CustomerID,OrderDate,ShippedDate,Freight

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Orders&

$select=OrderID,CustomerID,OrderDate,ShippedDate,Freight","value":[

{"OrderID":11075,"CustomerID":"RICSU","OrderDate":"1998-05-06T00:00:00",

"ShippedDate":null,"Freight":null},

{"OrderID":11076,"CustomerID":"BONAP","OrderDate":"1998-05-06T00:00:00",

"ShippedDate":null,"Freight":null},

{"OrderID":11077,"CustomerID":"RATTC","OrderDate":"1998-05-06T00:00:00",

"ShippedDate":null,"Freight":null}]}

COMSCI 335 / 2018 / v1 Page 6 of 8 radu&james

odata_xml_7

http://localhost:8181/A4CS.svc/Customers('ALFKI')?$format=json&$expand=Orders&$select=Custo

merID,ContactName,CompanyName,Orders/OrderID,Orders/ShipName,Orders/ShipCity,Orders/Ship

Country

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Customers/@Element&

$select=CustomerID,ContactName,CompanyName,

Orders/OrderID,Orders/ShipName,Orders/ShipCity,Orders/ShipCountry","Orders":[

{"OrderID":10643,"ShipName":"Alfreds Futterkiste","ShipCity":"Berlin","ShipCountry":"Germany"},

{"OrderID":10692,"ShipName":"Alfred's Futterkiste","ShipCity":"Berlin","ShipCountry":"Germany"},

{"OrderID":10702,"ShipName":"Alfred's Futterkiste","ShipCity":"Berlin","ShipCountry":"Germany"},

{"OrderID":10835,"ShipName":"Alfred's Futterkiste","ShipCity":"Berlin","ShipCountry":"Germany"},

{"OrderID":10952,"ShipName":"Alfred's Futterkiste","ShipCity":"Berlin","ShipCountry":"Germany"},

{"OrderID":11011,"ShipName":"Alfred's Futterkiste","ShipCity":"Berlin","ShipCountry":"Germany"}],

"CustomerID":"ALFKI","CompanyName":"Alfreds Futterkiste","ContactName":"Maria Anders"}

odata_xml_8

http://localhost:8181/A4CS.svc/Orders()?$format=json&$orderby=OrderID&$top=3&$expand=Cust

omer&$select=OrderID,CustomerID,Customer/ContactName,Customer/CompanyName

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Orders&

$select=OrderID,CustomerID,Customer/ContactName,Customer/CompanyName","value":[

{"Customer":{"CompanyName":"Vins et alcools Chevalier",

"ContactName":"Paul Henriot *******"},"OrderID":10248,"CustomerID":"VINET"},

{"Customer":{"CompanyName":"Toms Spezialit\u00e4ten",

"ContactName":"Karin Josephs"},"OrderID":10249,"CustomerID":"TOMSP"},

{"Customer":{"CompanyName":"Hanari Carnes",

"ContactName":"Mario Pontes"},"OrderID":10250,"CustomerID":"HANAR"}]}

odata_xml_9

http://localhost:8181/A4CS.svc/Orders()?$format=json&$orderby=OrderID&$top=3&$expand=Cust

omer&$select=OrderID,CustomerID,Customer/ContactName,Customer/CompanyName

{"odata.metadata":"http://localhost:8181/A4CS.svc/$metadata#Orders&

$select=OrderID,CustomerID,Customer/ContactName,Customer/CompanyName","value":[

{"Customer":{"CompanyName":"Vins et alcools Chevalier","ContactName":"Paul Henriot *******"},

"OrderID":10248,"CustomerID":"VINET"},

{"Customer":{"CompanyName":"Toms Spezialit\u00e4ten","ContactName":"Karin Josephs"},

"OrderID":10249,"CustomerID":"TOMSP"},

{"Customer":{"CompanyName":"Hanari Carnes","ContactName":"Mario Pontes"},

"OrderID":10250,"CustomerID":"HANAR"}]}

COMSCI 335 / 2018 / v1 Page 7 of 8 radu&james

Project folder structure

Your ODATA projects should keep the given skeleton structure!

In fact, you must NOT change anything else except the jbon007 source files!

o bin : compiler output, A4Y.dll, plus copies of the required libraries

o lib : required libraries

o data : XML documents

o _Compile A4XS.bat : compilation batch, jbon.svc.XS => .\bin\A4XS.dll

o _localhost-8181-A4XS.svc : URL shortcut to test if the service is running

o _Service_IISExpress_x64_8181.bat : starts IISExpress on port 8181 (64 bits)

o _Service_IISExpress_x86_8181.bat : starts IISExpress on port 8181 (32 bits)

o A4XS.svc : WCF processing directive, pointing to A4XS,A4XS (namespace,class)

o jbon007.svc.XS : source file – for you to write and rename (following the demo model)

o to test this, you also need to edit the source name in the compile batch (but you do

not need to submit the modified batch), e.g.

< set SOURCE=jbon007

> set SOURCE=apow001

o Web.config : service config file

Where X is either C (for C#) or F (for F#).

Running and testing

To run and test your service, you must follow the following steps:

1. Compile your source file with the given _Compile A4XS.bat; the resulting A4XS.dll will

be stored in the bin folder (together will all required libraries)

2. Start IISExpress with the appropriate batch

3. Optionally, double click on the _localhost-8181-A4XS.svc URL shortcut (which will start

the browser and display the two entities)

4. Continue testing, using your favourite WCF client: a browser, a browser add-on (such as

RESTClient in Firefox), Linqpad, …

COMSCI 335 / 2018 / v1 Page 8 of 8 radu&james

Development

Of course, we will NOT attempt to develop an ODATA service from scratch, even such a simple

service restricted to GET queries. Instead, we will “piggy-back” on extant libraries, which allow us to

fill in just our specific business requests – using various flavours of LINQ, i.e. in a crisp functional

way!

For development, we suggest the following tools: Notepad++, Linqpad or other light weight editors.

You are free to use VS, but your submitted project must NOT contain any trace of this and must still

have the indicated structure and behaviour!

Note that the model solution has about 100 well-spaced lines, so you probably do not need to write

more – much more than this may be a sign of a wrong approach.

Assignment Marks, Deliverables and Submission

This assignment is worth 5 total course marks. Please note the strict COMPSCI policy on plagiarism.

Submit electronically, to the COMPSCI web assignment dropbox, your two source files, named after

your UPI, e.g. jbon077.svc.cs and jbon007.svc.fs. The submission size will be limited to 20 KB per

student.

Please recheck your projects before submitting, starting from the archive prepared for submission

(which is the only thing that the marker will receive from you)!

You can submit several times, but only the last submission will be assessed. Please keep your

electronic dropbox receipt!

Deadline

Monday 1 Oct 2018, 18:00! Please do not leave it for the last minute. Remember that you can

resubmit and, by default, we only consider your last submission.

After this deadline, submissions will be still accepted for 4 more days, with gradually increasing

penalties, of 0.5% for each hour late. For example:

Monday 1 Oct 2018, 20:00: -1%, Tuesday 2 Oct 2017, 18:00: -12%

Tuesday 2 Oct 2018, 20:00: -13%, Wednesday 3 Oct 2017, 18:00: -24%

Thursday 4 Oct 2018, 18:00: -36%, Friday 5 Oct 2017, 18:00: -48%

After this, no more submissions are accepted!


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp