Wednesday 26 July 2017

NIIT Developing Windows Azure and Web Services Lab @ home 4 ~ GNIIT HELP

 Developing Windows Azure and Web Services Lab @ home 4 Ans 1
Implement the travelers' service by using ASP.NET Web API. Start by creating a new ASP.NET Web API controller, and implement CRUD functionality using the POST, GET, PUT and DELETE HTTP methods.
The main tasks for this exercise is to create a new API controller for the Destinations service and implement the controller actions.




To implement the required functionality, you need to perform the following steps:
1. Browse to the location where the Exercise 01 .zip file is saved.
2. Extract the files.
3. Press the Window logo key. The Start screen is displayed.
4. Start typing Visual Studio 2012.
5. Right-click the Visual Studio 2012 tile. The App bar is displayed.
6. Click the Run as administrator button on the App bar.
Note: If User Account Control dialog box is displayed, click the Yes button. If the current user account does not have administrative rights, the User Account Control dialog box prompts for the administrator credentials. In this case, specify the administrator credentials, and then click the Yes button.
7. Select FILE—Open—Project/Solution. The Open Project dialog box is displayed.
8. Browse to the location where the Exercise 01 .zip file is extracted.
9. Double-click the Exercise 01 folder.
10. Double-click the BlueYonder.Companion folder.
11. Select the BlueYonder.Companion.sln file.
12. Click the Open button. The BlueYonder.Companion - Microsoft Visual Studio window is displayed.
13. Ensure that the Solution Explorer window is opened.
14. Right-click the BlueYonder.Companion.Controllers node, and then select Add—New Item. The Add New Item -BlueYonder.Companion.Controllers dialog box is displayed.
15. Select Web under the Visual C# Items node in the left pane.
16. Ensure that Web API Controller Class is selected in the middle pane.
17. Select and replace the existing text in the Name textbox with TravelersController.
18. Click the Add button. The TravelersController.es file is displayed.
19. Type the highlighted portions of the following code snippet in the TravelersController.es file: using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BlueYonder.Entities;
using BlueYonder.DataAccess.Interfaces;
using BlueYonder.DataAccess.Repositories;
20. Replace the existing code within the TravelersController class in the TravellerController.es file with the following code snippet:
private ITravelerRepository Travelers { get; set; } public TravelersController()
{
Travelers = new TravelerRepository();
}
public HttpResponseMessage Get(string id)
{
var traveler = Travelers.FindBy(t => t.TravelerUserldentity = id).FirstOrDefault();
//Handling the HTTP status codes if (traveler != null)
return Request.CreateResponse<Traveler>(HttpStatusCode.OK, t
else
return Request.CreateResponse(HttpStatusCode.NotFound);
}
public HttpResponseMessage Post(Traveler traveler)
{
//Saving the new order to the database Travelers.Add(traveler);
Travelers.Save();
// creating the response, the newly saved entity and 201 Created var response = Request.CreateResponse(HttpStatusCode.Created, tr response.Headers.Location = new Uri(Request.RequestUri, traveler.TravelerId.ToString());
return response;
}
public HttpResponseMessage Put(String id, Traveler traveler)
{
// returning 404 if the entity doesn’t exist
if (Travelers.FindBy(t => t .TravelerUserldentity == id). FirstOrDe-f
null)
return Request.CreateResponse(HttpStatusCode.NotFound);
Travelers.Edit(traveler);
Travelers.Save();
return Request.CreateResponse(HttpStatusCode.OK);
}
public HttpResponseMessage Delete(St ring id)
{
var traveler = Travelers.FindBy(t => t.TravelerUserldentity id). FirstOrDefaultQ;
// returning 404 if the entity doesn’t exist if (traveler == null)
return Request.CreateResponse(HttpStatusCode.NotFound); Travelers.Delete(traveler);
Travelers.Save();
return Request.CreateResponse(HttpStatusCode.OK);
}
21. Ensure that the Solution Explorer window is opened.
22. Ensure that the BlueYonder.Companion.Host node is expanded.
23. Double-click the Web.config file under the BlueYonder.Companion.Host node. The Web.config file is displayed.
24. Locate the text User ld=BlueYonder;Password=Pa$$wOrd; in the connection string, and replace it with User ld=sa;Password=password@123; in the Web.config file.
25. Select FILE—Save All to save the changes.
26. Close Microsoft Visual Studio 2012.





Developing Windows Azure and Web Services Lab @ home 4 Ans 2


Consume the travelers' service from the client application. Start by implementing the GetTravelerAsync method by invoking a GET request to retrieve a specific traveler from the server. Continue by implementing the CreateTravelerAsync method by invoking a POST request to create a new traveler. And complete the exercise by implementing the UpdateTravelerAsync method by invoking a PUT request to update an existing traveler.The main tasks for this exercise are:

1. Use System.Net.HttpCIient to get a list of destinations from the Destinations service.
2. Debug the BlueYonder.Companion.Client project.

To implement the required functionality, you need to perform the following steps:
1. Browse to the location where the Exercise 02.zip file is saved.
2. Extract the files.
3. Open Microsoft Visual Studio 2012.
4. Select FILE—Open—Project/Solution. The Open Project dialog box is displayed.
5. Browse to the location where the Exercise 02.zip file is extracted.
6. Double-click the Exercise 02 folder.
7. Double-click the BlueYonder.Companion.Client folder.
8. Select the BlueYonder.Companion.Client.sln file.
9. Click the Open button. The BlueYonder.Companion.Client - Microsoft Visual Studio window is displayed.
10. Select VIEW—Task List. The Task List window is displayed.
11. Select Comments from the Categories drop-down list in the Task List window.
12. Double-click the TODO: Exercise 2: Task 1a: implement the method by getting a traveler from the server comment under the Description column of the Task List window. The DataManager.es file is displayed.
13. Delete the highlighted portion of the following code snippet in the DataManager.es file:/// <summary>/// Get the traveler associated with this machine III </summary>III <returnsx/returns>public async Task<Traveler> GetTravelerAsync(){// TODO: 
Exercise 2: Task la: implement the method by getting a traveler from the serverthrow new NotlmplementedException();}
14. Type the highlighted portion of the following code snippet in the DataManager.es file: public async Task<Traveler> GetTravelerAsyncQ {// TODO: 
Exercise 2: Task la: implement the method by getting a traveler from the servervar hardwareld = GetHardwareld();HttpClient client = new HttpClient();var travelersllri = string. Format("{0}travelers/{1}", BaseUri, hardwareld) HttpResponseMessage response = await client.GetAsync(new Uri(travelersUri if (response.IsSuccessStatusCode){string resultlson = await response.Content. ReadAsStringAsync();return await IsonConvert.DeserializeObjectAsync<Traveler>(resultJson)}else{return null;}
15. Right-click the first line of code after the comment line in the GetTravelerAsync() method, and then select Breakpoint—Insert Breakpoint.
16. Double-click the TODO: Exercise 2: Task 1b: implement the method by using the HttpCIient class to invoke a POST request sending the traveler DTO comment under the Description column of the Task List window.
17. Delete the highlighted portion of the following code snippet in the DataManager.es file:public async Task<Traveler> CreateTravelerAsync(){// TODO: Exercise 2: Task lb: implement the method by using the HttpClier class to invoke a POST request sending the traveler DTO throw new NotlmplementedExceptionQ;}
18. Type the highlighted portion of the following code snippet in the DataManager.es file: public async Task<Traveler> CreateTravelerAsyncQ{// TODO: Exercise 2: Task lb: implement the method by using the HttpClien class to invoke a POST request sending the traveler DTO var dto = new TravelerDTOQ {TravelerUserldentity = GetHardwareld()hstring json = JsonConvert.SerializeObject(dto);HttpCIient client = new HttpClientQ; var content = new StringContent(json);content.Headers.ContentType = new MediaTypeHeaderValue("application/json" HttpResponseMessage response = await client.PostAsync(new Uri(_createTravelerUri), content);var resultlson = await response.Content. ReadAsSt ringAsyncQ;return await JsonConvert.DeserializeObjectAsync<Traveler>(resultJson);}
19. Right-click the first line of code after the comment in the CreateTravelerAsyncO method, and then select Breakpoint—Insert Breakpoint.
20. Double-click the TODO: 
Exercise 2: Task 1c: implement the method by using the HttpCIient class to invoke a PUT request sending the traveler DTO comment under the Description column of the Task List window.
21. Delete the highlighted portion of the following code snippet in the DataManager.es file:/// <summary>III Modify the traveler details III </summary>III <param name="traveler">The Traveler</param>III <returnsx/returns>public async Task UpdateTravelerAsync(Traveler traveler){if (lawait NetworkManager.CheckInternetConnection(true, "")) return;// TODO: 
Exercise 2: Task lc: implement the method by using the HttpCIient class invoke a PUT request sending the traveler DTO throw new NotlmplementedExceptionQ;}
22. Type the highlighted portion of the following code snippet in the DataManager.es file: public async Task UpdateTravelerAsync(Traveler traveler){if (lawait NetworkManager.CheckInternetConnection(true, "")) return;// TODO: 
Exercise 2: Task lc: implement the method by using the HttpClient class invoke a PUT request sending the traveler DTO var dto = traveler.ToDTO(); dto.TravelerUserldentity = GetHardwareldQ; string json = IsonConvert.SerializeObject(dto);HttpClient client = new HttpClient(); var content = new StringContent(json);content.Headers.ContentType = new MediaTypeHeaderValue("application/json" var travelerUri = string.Format("{0}/travelers/{l}">BaseUri, dto.TravelerUserIdentity);await client.PutAsync(new Uri(travelerUri), content);}
23. Right-click the first line of code in the UpdateTravelerAsync() method, and then select Breakpoint—Insert Breakpoint.
24. Locate the string http://10.10.0.10/BlueYonder.Companion.Host/ and replace it with http://localhost/BlueYonder.Companion.Host/ in the DataManager.es file.
25. Select FILE—Save All to save the changes.
26. Press the Window logo key. The Start screen is displayed.
27. Start typing Visual Studio 2012.
28. Right-click theVisual Studio 2012 tile.The App bar is displayed.
29. Click the Run as administrator button on the App bar.
30. Select FILE—Open—Project/Solution. The Open Project dialog box is displayed.
31. Browse to the location where the Exercise 02.zip file is extracted.
32. Double-click the Exercise 02 folder.
33. Double-click the BlueYonder.Companion folder.
34. Select the BlueYonder.Companion.sln file.
35. Click the Open button. The BlueYonder.Companion - Microsoft Visual Studio window is displayed.
36. Ensure that the Solution Explorer window is opened.
37. Select DEBUG—Start Debugging. The Internet Explorer window is displayed.
38. Switch to BlueYonder.Companion.Client - Microsoft Visual Studio window.
39. Select DEBUG—Start Debugging. The BlueYonder Companion app's splash screen is displayed for a few seconds, and then the code execution breaks inside the GetTravelerAsync() method. In addition, the line in breakpoint is highlighted in yellow.
40. Press the F5 key to continue. Similarly, the code execution breaks at several places where you have added the breakpoints. You need to press the F5 key to continue the execution wherever it is interrupted because of the breakpoint until the BlueYonder Companion app is launched.
41. Click the Allow button, if you are prompted to allow the app to run in the background.
42. Right-click on the blank area of the app screen. The App bar is displayed at the bottom of the screen.
43. Click the Search button on the App bar. and then type New in the Search box.
44. Click the Allow button if you are prompted to allow the app to share your location. Wait for the app to show a list of flights from Seattle to New York.
45. Click Purchase this trip. The Purchase page is displayed.
46. Type your first name in the First Name text box.
47. Type your last name in the Last Name text box.
48. Type Aa1234567 in the Passport text box.
49. Type 555-5555555 in the Mobile Phone text box.
50. Type 423 Main St. in the Home Address text box.
51. Type your email address in the Email Address text box.
52. Click the Purchase button. If the code execution breaks, press the F5 key to continue.
53. Click the Close button when the message dialog is displayed.
54. Close the BlueYonder Companion app.
55. Switch to BlueYonder.Companion - Microsoft Visual Studio window.
56. Press the Shift+F5 keys to stop debugging the application.
57. Close both the Microsoft Visual Studio 2012 windows.

No comments:

Post a Comment