DPS907 WSA500 Tests and Sample Answers

Sample answers for the weekly tests for the Fall 2017 term. The most recent test is at the top of the page.

When your test is marked, we are looking for an answer that captures the essence of the example answers (in red, below). Your answer does not necessarily have to be exactly the same, and part marks are possible. You should strive to improve your explanations, as that will improve your academic and career prospects.

Most tests are worth 4% of your final course grade. Typically, there are about 7 questions on the test, and you will give answers to any 4 questions.

 

Test 2, September 14

1. The request-handling pipeline concept is important for any web app, and especially for a web service. Using a numbered list, or a simple diagram, name and/or describe the notable components in the pipeline.

Incoming request…
1. Operating system listener on TCP port 80 and 443
2. Web server 
3. ASP.NET runtime, with front controller, router, and deserializer (model binder)
4. Request-handling controller
5. Typically, manager and data persistence
6. Response serializer (media formatter)

2. Consider this scenario: A web service controller method returns a result that has an associated object or collection. Is the coding any different from a result that does not include an associated object or collection? Explain.

No.
The response serializer (media formatter) simply accepts and works on the object graph, without regard to its shape (however, the object graph must not contain any circular references).

3. Assume that you are writing the classes for two associated entities. It is possible to configure a navigation property as “required”. Why would you do that? What effect does it have on your coding task, and/or on the stored object?

Why? To prevent an object that depends upon another from being created if you do not have a reference to the associated object. 
Or, when you must have a reference to the “required” associated object. 
For example, adding an object on the “to many” side needs a reference to the “to one” object. 
Effect? In the data store, the foreign key property constraint gets configured by the EF façade and manager.

4. Explain or discuss the role of attribute routing for controller methods; can use/contrast the code example’s methods that return results with/without associated object(s).

Typically used to add features to a controller’s resource URIs. 
Base URI often designed to return a base or typical representation.
Additional URI often used to return an enhanced version of the base or typical representation.

5. A controller’s get all or get one method usually returns the Ok() extension method. However, an add new method returns the Created() extension method. Why? What benefit or value does it provide?

The response pipeline configures the HTTP status code to 201.
And it configures a Location response header.
The requestor now has a richer response, with helpful metadata.

6. Assume you are writing a design model class that has a to-one navigation property. What code is added for that nav property, and why? Be as specific and correct as you can.

Data annotation, [Required].
Property type is the associated class, and name is singular.

7. Assume that you are writing a resource model class that has a to-many navigation property. What code is added for that nav property, and why? Be as specific and correct as you can.

Property type is an IEnumerable<T> of the associated class, and name is plural.
No data annotation, but the collection is initialized in the default constructor.

 

Test 1, September 7

1. Briefly explain the value proposition (i.e. what makes it attractive) of the IHttpActionResult type, when compared to simply returning an object or collection.

The request-handling pipeline configures the response with the correct HTTP status code.
Or, coding consistency. The helper methods (OK, NotFound, etc.) are more expressive.

2. Briefly describe how request routing works in Web API. (Or put another way, how does ASP.NET Web API route HTTP requests to controllers?)

App domain uses the front controller pattern to receive the request.
Front controller inspects the URI, and compares it to routes defined by the app (and also by convention in the runtime).
Then, it attempts to locate a matching route, based on reflection over all the controller types found in the app.
The matching controller is initialized, and the matching method is called with the request’s data.

3. Scenario: A user agent requests (GET) a collection resource. There are no items in the collection. What is the correct response, and why?

HTTP 200 OK
The data package will be an empty container.
The absence of objects in the collection does not imply an error condition. It simply means that the collection resource is empty.

4. Write a brief and clear definition any two of the following:
Web service, Request, Response, Resource, Representation, Internet Media Type, JSON, XML.

See the “terminology” section of the notes.

5. Briefly describe the purpose of content negotiation, and briefly describe how it works.

The process of requesting the desired representation for a response, in situations where there are multiple representations available.
The request includes an “Accept” header.
If the requested representation is available, the server prepares and sends the response.
The response includes a “Content-Type” header.

6. Briefly explain the difference (or relationship) between resource and representation.

Resource is a digital asset.
Representation is a digital asset that is formatted as a specific internet media type.

7. Briefly explain the purpose of HTTP response status codes 200, 201, and 204.

200 – successful request, almost always with an entity body. Most often used with GET.
201 – resource was successfully created, includes an entity body. Most often used with POST.
204 – successful request (but no entity body)

 

 

 

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Advertisements
%d bloggers like this: