Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a REST-based web service that stores phone book enteries in a database. (

ID: 3693471 • Letter: C

Question

Create a REST-based web service that stores phone book enteries in a database. (PhoneBook.mdf, which is provided in the examples directory for this chapter) and a client application that consumes this service. Give the client user the capability to enter a new contact (service method AddEntry) and to find contacts by last name (service method GetEnteries). Pass only primitive types as arguments to the web service. Add a DataContext to the web service project to enable the web service to interact with the database. The GetEntries method should return an array of strings that contains the matching phone book entries. Each string in the array should consist of the last name, first name, and phone number for one phone book entry seperated by commas. Build an ASP.NET client to interact with this web service. To use an asynchronous web request from ASP.NET client, you must set the Async property to true by adding the Async="true" to the .aspx page directive. Since the AddEntry method accepts a request and does not return a response to the client, you can use WebClient's OpenRead method to access the service method. You can use the ToArray method on the LINQ query to return an array containing LINQ query results. (This is for a web development style)

Explanation / Answer

Ans;

SELECT LastName, FirstName, PhoneNumber
FROM PhoneBook
WHERE (LastName = LastName)
The INSERT statement that inserts a new entry into the PhoneBook database should be:

INSERT INTO PhoneBook (LastName, FirstName, PhoneNumber)
VALUES (LastName, FirstName, PhoneNumber)
[Note: Here is the SQL code to create the database]

DROP TABLE PhoneBook;
CREATE TABLE PhoneBook
(
FirstName VARCHAR (50) NOT NULL,
LastName VARCHAR (50) NOT NULL,
PhoneNumber VARCHAR (50) NOT NULL
);
INSERT INTO PhoneBook (FirstName,LastName,PhoneNumber)
VALUES ('Bob', 'Green', '5555551111'),
('Sue', 'Black', '5555552222'),
('Liz', 'White', '5555553333'),
('Paul', 'Blue', '5555554444')