Likes

Developing Windows Azure and Web Services Lab @ 6 Ans 1

OData is a data access protocol that provides standard CRUD access of a data source via a website. To add support for OData protocol you will install a NuGet Microsoft.AspNet.WebApi.OData package, and then decorate the methods that you want to support OData with [Queryable] attribute.
The main tasks for this exercise are:
1. Add a queryable action to the flight schedule service.
2. Handle the search event in the client application and query the flight schedule service by using OData filters.




Task 1: Adding a queryable action to the flight schedule service
To add a queryable action to the flight schedule service, you need to perform the following steps:
1. Browse to the location where the Exercise 03.zip file is saved.
2. Extract the files.
3. Press the Windows logo key. The Start screen is displayed.
4. Start typing Visual Studio 2012. The Search pane and Apps screen are displayed.
5. Right-click the Visual Studio 2012 tile, and then select Run as Administrator.
6. Select FILE—Open—Project-Solution. The Open Project dialog box is displayed.
7. Browse to the location where the Exercise 03 folder is extracted.
8. Double-click the Exercise 03 folder.
9. Double-click the BlueYonder.Companion folder.
10. Select the BlueYonder.Companion.sin file.
11. Click the Open button. The BlueYonder.Companion - Microsoft Visual Studio window is displayed.
12. Ensure that the Solution Explorer window is opened.
13. Click the TOOL S menu on the toolbar, and then select Library Package Manager—Package Manager Console. The Package Manager Console window is displayed.
14. Type install-package Microsoft.AspNet.WebApi.OData -version 0.1.0-alpha-120815 -ProjectName BlueYonder.Companion.Controllers, and then press the Enter key.
15. Wait until Package Manager Console finished downloading and adding the package.
16. Ensure that the Solution Explorer window is opened.
17. Expand the BlueYonder.Companion.Controllers node.
18. Double-click the LocationsController.es file. The LocationsController.es file is displayed.
19. Replace the existing Get? {) method, which has the three parameters with the following code snippet in the LocationsController.es file:
[Queryable]
public IQueryable<Location> Get()
{
return Locations.GetAll();
}
20. Select FILE—Save All to save the changes.
21. Close Microsoft Visual Studio 2012.
Task 2: Handling the Search Event in the Client Application and Query the Flight Schedule Service by Using OData filters
To handle the search event in the client application and query the flight schedule service by Using OData filters, you need to perform the following steps:
1. Press the Windows logo key. The Start screen is displayed.
2. Start hyping Visual Studio 2012. The Search pane and Apps screen are displayed.
3. Right-click the Visual Studio 2012 tile, and then select Run as Administrator.
4. Select FILE—Open—Projecb'Solution. The Open Project dialog box is displayed.
5. Browse to the location where the Exercise 03 folder is extracted.
6. Double-click the Exercise 03 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. Ensure that Solution Explorer window is opened.
11. Expand the BlueYonder.Comapanion.Shared node.
12. Double-click the Addresses.es file. The Addresses.es file is displayed.
13. Replace the return statement of the GetLocationsWithQueryUri property with the following code snippet:
return GetLocationsUri + M?Sfilter=substringof(tolower(,{0},),tolower(City))";
14. Select FILE— Save All to save the changes.
15. Close Microsoft Visual Studio 2012.

Developing Windows Azure and Web Services Lab @ 5 Ans 2

To support RSS feeds of flight schedule you will create a new media type that handles the RSS requests, and then register the new media formatter class in the Http Configuration formatters.
The main tasks for this exercise are:
1. Create a new class that derives from MediaTypeFormatter.
2. Implement the necessary code to return an RSS response containing flight schedule information.
3. Register the new media formatter.
4. Use Internet Explorer to view the feed.



Task 1: Creating a New Class that Derives from MediaTypeFormatter
To create a new class that derives from MediaTypeFormatter. 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. Press the Windows 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.
7. Select FILE—Open—Project-Solution. The Open Project dialog box is displayed.
8. Browse to the location where the Exercise 02 folder is extracted.
9. Double-click the Exercise 02 folder.
10. Double-click the BlueYonder.Companion folder.
11. Select the BlueYonder.Companion.sin file.
12. Click the Open button. The BlueYonder.Companion - Microsoft Visual Studio (Administrator) 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 Folder.
15. Replace the existing text of the folder name with Formatters, and then press the Enter key.
16. Right-click the Formatters folder, and then select Add—Class. The Add New Item -BlueYonder.Companion.Controllers dialog box is displayed.
17. Select and replace the existing text in the Name text box with Atom Formatter.
18. Click the Add button. The AtomFormatter.es file is displayed.
19. Type the highlighted portions of the following code snippet in the AtomFormatter.es file:
using System;
using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml;
using BlueYonder.Companion.Entities; using System.Net.Http; using System.Net.Http.Formatting; using System.Net.Http.Headers; using System.ServiceModel.Syndication;
namespace BlueYonder.Companion.Controllers.Formatters
{
public class AtomFormatter : MediaTypeFormatter
{
}
}
20. Select FILE— Save All to save the changes.
Task 2: Implementing the Necessary Code to Return RSS Response Containing Flight Schedule Information
To implement the necessary code to return RSS response containing flight schedule information, you need to perform the following steps:
1. Ensure that Solution Explorer window is opened.
2. Ensure that the AtomFormatter.es file is opened.
3. Type the highlighted portions of the following code snippet in the AtomFormatter.es file:
class AtomFormatter : MediaTypeFormatter
{
private HttpRequestMessage request;
//Add the new media type header to the supported media types, public AtomFormatterQ {
SupportedMediaTypes.Add(new MediaTypeHeaderValue ("application/atom+xml") );
>
//Is used to receive the instance of the HttpRequestMessage class, public AtomFormatter(HttpRequestMessage request)
{
_request - request;
}
//Overrides the CanReadType method, to define it is not supporting deseriali public override bool CanReadType(Type type)
{
return false;
}
//Overrides the CanWriteType method, to define it supports serialization of FlightWithSchedulesDTO class instances.
public override bool CanWriteType(Type type)
{
>
return type == typeof(FlightWithSchedulesDTO);
private SyndicationFeed CreateFeed(FlightWithSchedulesDTO flight)
{
var feed = new SyndicationFeed
{
Title = new TextSyndicationContent(string.Format("Blue Yonder flight {0}", flight.FlightNumber))
};
var items = from s in flight.Schedules select new Syndicationltem
{
Title = new TextSyndicationContent(
String.Format("Flight {0} {1}", flight.FlightNumber, s.Departure.ToString(”MMMM dd, yyyy")))>
Id = flight.FlightNumber,
BaseUri = new Uri(_request.RequestUri, string.Format("{0}/{1}",
_request.RequestUri.AbsolutePath, flight.FlightNumber)),
>;
feed.Items - items; return feed;
}
public override Task WriteToStreamAsync(Type type, object value, System.10 writeStream, RttpContent content, System.Net.TransportContext transportContext)
{
// creating a System.ServiceModel.Syndication.SyndicationFeed var feed - CreateFeed(value as FlightWithSchedulesDTO);
return Task.Run(() =>
{
using (var writer = XmlWriter.Create(writeStream))
{
Atoml0FeedFormatter atomformatter = new Atoml0FeedFormatter(fe< atomformatter.WriteTo(writer);
}
»;
}
//Overrides the base GetPerRequestFormatterlnstance method, to create a nei instance of the AtomFormatter class for each atom request.
public override MediaTypeFormatter GetPerRequestFormatterInstance(Type typ< HttpRequestMessage request,
MediaTypeHeaderValue mediaType)
{
return new AtomFormatter(request);
}
}
}
4. Select FILE— Save All to save the changes.
Task 3: Registering the New Media Formatter
ro register the new media formatter, you need to perform the following steps:
1. Ensure that Solution Explorer window is opened.
2. Expand the BlueYonder.Companion.Host node.
3. Expand the App_Start folder.
4. Double-click the WebApiConfig.es file. The WebApiConfig.es file is displayed.
5. Type the highlighted portions of the following code snippet in the WebApiConfig.es file:
using System.Web.Http.Routing; using System.Net.Http;
using BlueYonder.Companion.Controllers.Formatters;
namespace BlueYonder.Companion.Host
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Formatters.Add(new AtomFormatterQ); config.DependencyResolver ■ new BlueYonderResolverQ; config.MessageHandlers.Add(new AtomHandler()>;
6. Select FILE— Save All to save the changes.
Task 4: Using Internet Explorer to View the Feed
To use Internet Explorer to view the feed, you need to perform the following steps:
1. Ensure that Solution Explorer window is opened.
2. Ensure that the BlueYonder.Companion.Host project is set as startup project.
3. Press the F5 key. The Internet Explorer window is displayed.
4. Append atom/flights/1 to the address in the address bar. and then press the Enter key. The details of a flight are
5. Switch to Microsoft Visual Studio 2012.
6. Press the Shift+F5 keys.
7. Close Microsoft Visual Studio 2012.

Developing Windows Azure and Web Services Lab @ 5 Ans 1

The first step in creating a WCF service is to define the service contract and data contracts. Only afterwards you can begin implementing the serv ice contract. In this exercise, you will define a service contract niter face for the booking service along with the required data contracts, and then you will implement the service contract.
The main tasks for this exercise are:
1. Create a data contract for the booking request.
2. Create a service contract for the booking service.
3. Implement the service contract.




To implement the required functionality, you need to perform the following tasks:
1. Create a data contract for the booking request.
2. Create a service contract for the booking service.
3. Implement the service contract.
Task 1: Creating a Data Contract for the Booking Request
To create a data contract for the booking request, 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. Double-click the Exercise 01 folder.
4. Double-click the BlueYonder.Server folder.
5. Double-click the BlueYonder.Server.sln file. The BlueYonder.Server - Microsoft Visual Studio window is displayed.
6. Ensure that the Solution Explorer window is opened.
7. Right-click the BlueYonder.BookingService.Contracts node, and then select Add Reference. The Reference Manager - BlueYonder.BookingService.Contracts dialog box is displayed.
8. Ensure that the Assemblies node is expanded in the left pane.
9. Ensure that the Framework node is selected.
10. Scroll down and select the check boxes next to the following assembly names in the middle pane:
o System.Runtime.Serialization * System. ServiceModel
11. Click the OK button.
12. Right-click the BlueYonder.BookingService.Contracts node, and then select Add—Class. The Add New Item -BlueYonder.BookingService.Contracts dialog box is displayed.
13. Ensure that Class is selected in the middle pane.
14. Select and replace the existing text in the Name text box with TripDto.
15. Click the Add button. The TripDto.cs file is displayed.
16. Type the highlighted portions of the following code snippet in the TripDto.es file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using BlueYonder.Entities;
namespace BlueYonder.BookingService.Contracts
{
[DataContract] public class TripDto {
[DataMember]
public int FlightSchedulelD { get; set; }
[DataMember]
public FlightStatus Status { get; set; }
[DataMember]
public SeatClass Class { get; set; }
>
>
17. Select FILE—Save All to save the changes.
18. Ensure that the Solution Explorer window is opened.
19. Right-click the BlueYonder.BookingService.Contracts node, and then select Add—Class. The Add New Item -BlueYonder.BookingService.Contracts dialog box is displayed.
20. Ensure that Class is selected in the middle pane.
21. Select and replace the existing text in the Name text box with ReservationDto.
22. Click the Add button. The ReservationDto.es file is displayed.
23. Type the highlighted portions of the following code snippet in the ReservationDto.es file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace BlueYonder.BookingService.Contracts
{
[OataContract] public class ReservationDto
{
[DataMember]
public int Travelerld { get; set; }
[DataMember]
public DateTime ReservationDate { get; set; }
[DataMember]
public TripDto DepartureFlight { get; set; }
[DataMember]
public TripDto ReturnFlight { get; set; }
}
}
24. Select FILE— Save All to save the changes.
25. Ensure that the Solution Explorer window is opened.
26. Right-click the BlueYonder.Booking Service.Contracts node, and then select Add—New Folder.
27. Replace the existing text of the folder name with Faults, and then press the Enter key.
28. Right-click the Faults folder, and then select Add—Class. The Add New Item -BlueYonder.Booking Service.Contracts dialog box is displayed.
29. Ensure that Class is selected in the middle pane.
30. Select and replace the existing text in the Name text box with ReservationCreationFault.
31. Click the Add button. The ReservationCreationFault.es file is displayed.
32. Type the highlighted portions of the following code snippet in the ReservationCreationFault.es file: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace BlueYonder.BookingService.Contracts.Faults
{
[DataContract]
public class ReservationCreationFault
{
[DataMember]
public string Description { get; set; }
[DataMember]
public DateTime ReservationDate { get; set; }
}
}
33. Select FILE— Save All to save the changes.
Task 2: Creating a Service Contract for the Booking Service
To create a service contract for the booking service, you need to perform the following steps:
1. Ensure that Solution Explorer window is opened.
2. Right-click the BlueYonder.Booking Service.Contracts node, and then select Add—New Item. The Add New Item -BlueYonder.Companion.Controllers dialog box is displayed.
3. Select Interface in the middle pane.
4. Select and replace the existing text in the Name text box with IBooking Service.
5. Click the Add button. The IBooking Service.cs file is displayed.
6. Type the highlighted portions of the following code snippet in the IBooking Service.cs file:
using System;
using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ServiceModel;
using BlueYonder.BookingService.Contracts.Faults;
namespace BlueYonder.BookingService.Contracts
{
[ServiceContract(Namespace = "http://blueyonder.server.interfaces/")] public interface IBookingService {
[OperationContract]
[FaultContract(typeof(ReservationCreationFault))] string CreateReservation(ReservationDto request);
>
}
7. Select FILE— Save All to save the changes.
Task 3: Implementing the Service Contract
To implement the service contract, you need to perform the following steps:
1. Ensure that Solution Explorer window is opened.
2. Right-click the BlueYonder.Booking Service.lmplementation node, and then select Add Reference. The Reference Manager - BlueYonder.Booking Service.lmplementation dialog box is displayed.
3. Ensure that the Framework node is selected in the left pane.
4. Scroll down and select the check box next to the System.ServiceModel assembly in the middle pane.
5. Click the OK button.
6. Right-click the BlueYonder.Booking Service.lmplementation node, and then select Add—Class. The Add New Item -BlueYonder.BookingService.Implementation dialog box is displayed.
7. Ensure that Class is selected in the middle pane.
8. Select and replace the existing text in the Name text box with Booking Service.
9. Click the Add button. The Booking Service.cs file is displayed.
10. Type the highlighted portions of the following code snippet in the BookingService.es file: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using BlueYonder.BookingService.Contracts;
using BlueYonder.BookingService.Contracts.Faults;
using BlueYonder.DataAccess.Interfaces;
using BlueYonder.DataAccess.Repositories;
using BlueYonder.Entities;
namespace BlueYonder.BookingService.Implementation
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class BookingService : IBookingService
{
}
}
11. Add the following code snippet inside the BookingService class:
public static readonly string ConnectionName = "BlueYonderServer"; public string CreateReservation(ReservationDto request)
{
if (request.DepartureFlight == null)
{
throw new FaultException<ReservationCreationFault>( new ReservationCreationFault {
Description = "Reservation must include a departure flight", ReservationDate = request.ReservationDate }, "Invalid flight info");
}
var reservation - new Reservation
{
Travelerld = request.Travelerld,
ReservationDate - request.ReservationDate,
DepartureFlight = new Trip
{
Class - request.DepartureFlight.Class,
Status = request.DepartureFlight.Status,
FlightSchedulelD - request.DepartureFlight.FlightSchedulelD
}
};
if (request.ReturnFlight !- null)
{
reservation.ReturnFlight - new Trip
{
Class = request.ReturnFlight.Class,
Status ■ request.ReturnFlight.Status,
FlightSchedulelD = request.ReturnFlight.FlightSchedulelD
};
}

using (IReservationRepository reservationRepository - new ReservationRepository(ConnectionName))
{
reservation.ConfirmationCode -
ReservationUtils.GenerateConfirmationCode(reservationRepository); reservationRepository.Add(reservation); reservationRepository. Save(); return reservation.ConfirmationCode;
}
}
12. Right-click the first line of code in the CreateReservation method, and then select Breakpoint—Insert Breakpoint.
13. Select FILE—Save All to save the changes.
14. Press the F6 key. and ensure that the Build successed message is displayed on the status bar.
15. Close Microsoft Visual Studio 2012.

Developing Windows Azure and Web Services Lab @ 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 server
throw 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 server
var 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()
h
string 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.

Developing Windows Azure and Web Services Lab @ 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 @ 3 Ans 2

Modify the BlueYonder.FlightDetails project to allow users to update the schedule departure of specific flight.



To implement the required functionality, you need to perform the following tasks:
1. Browse to the location where the Exercise 04.zip file is saved.
2. Extract the files.
3. Double-click the Exercise 04 folder.
4. Double-click the BlueYonder.Companion folder.
5. Double-click the BlueYonder.Companion.sin file. The BlueYonder.Companion - Microsoft Visual Studio window displayed.
6. Ensure that the Solution Explorer window is opened.
7. Ensure that the BlueYonder.FlightDetails node is expanded.
8. Double-click the Program.es file within the BlueYonder.FlightDetails node. The Program.es file is displayed.
9. Type the highlighted portions of the following code snippet in the Program.es file:
if (flightDetails != null)
{
Console.WriteLine("The flight starts from " + flightDetails.Source.City H ”, " + flightDetails.Source.Country + " for " + flightDetails.Destination.City + ”, " + flightDetails.Destination.Country +
}
else
{
Console.WriteLine("Invalid Flight Number.");
>
Console.WriteLine("\nDo you want to update the Flight Schedule? Enter Yes or
No");
string ans = Console.ReadLine(); if (ans.ToLower() == "yes")
{
Console.WriteLine("Enter the date in the MM/DD/YYYY format:"); string date = Console.ReadLine();
Console.WriteLine("Enter the time in the HH:MM:SS format:");
string time = Console.ReadLineQ;
string dateTime = date + " " + time;
foreach (var item in flightDetails.Schedules)
{
item.Departure = Convert.ToDateTime(dateTime)j bdbc .SaveChangesQi
}
Console.WriteLine("\nFlight Schedule is updated")$
}
Console.WriteLine("\nPress the ENTER key to close the application.") Console .ReadLineQ ;
10. Select FILE—Save All to save the changes
11. Select TEST—Windows—Test Explorer The Test Explorer window is displayed
12. Click Run All, and then wait for all the tests to complete.
13. Press the F5 key The output is displayed,
14. Enter a flight number, and then press the Enter key. The details of the specified flight is displayed.
15. Enter Yes. and then press the Enter key to update the flight schedule.
16. Enter the date in the specified format, and then press the Enter key.
17. Enter the time in the specified format, and then press the Enter key. The flight schedule is updated.
18. Press the Enter key to close the Console window.
19. Open SQL Server Management Studio, and connect to the ASQLExpress database server.
20. Expand the Databases node in the Object Explorer window, and then expand the BlueYonder.Companion.Lab02
database.
21. Expand the Tables nodes.
22. Right-click the FlightSchedules table, and then select Select Top 1000 Rows. The FlightSchedules table is displayed with updated record.
23. Close the SQL Server Management window.
24. Switch to Microsoft Visual Studio 2012, and close it.

Developing Windows Azure and Web Services Lab @ 3 Ans 1

Implement the functionality to query the source and destination information of a specific flight by providing the flight number. Start by creating a new Console application project, and use WhereQ extension method of LINQto Entities.



To implement the required functionality, you need to perform the following steps:
1. Browse to the location where you have saved the Exercise 03.zip file.
2. Extract the files.
3. Double-click the Exercise 03 folder.
4. Double-click the BlueYonder.Companion folder.
5. Double-click the BlueYonder.Companion.sin file. The BlueYonder.Companion - Microsoft Visual Studio window displayed.
6. Select FILE—Add—New Project The Add New Project window is displayed.
7. Ensure that the Installed—Visual C# nodes are expanded in the left pane.
8. Select the Windows node in the left pane.
9. Select the Console Application template in the middle pane.
10. Ensure that the framework selected for the project is .NET Framework 4.5
11. Select and replace the existing text in the Name text box with BlueYonder.FlightDetails
12. Click the OK button. The Program.es file is displayed.
13. Ensure that the Solution Explorer window is opened.
14. Right-click the BlueYonder.FlightDetails node, and then select Add Reference The Reference Manager -BlueYonder.FlightDetails dialog box is displayed.
15. Ensure that the Assemblies node is expanded in the left pane.
16. Ensure that the Framework option is selected in the left pane.
17. Type System.Data.Entity in the Search Assemblies combo box.
18. Select the System.Data.Entity option under the Name column in the middle pane.
19. Select the System.Data.Entity check box.
20. Select the Solution node in the left pane.
21. Select the BlueYonder.Entities option under the Name column in the middle pane.
22. Select the BlueYonder.Entities check box.
23. Click the OK button.
24 Right-click the BlueYonder.FlightDetails node, and then select Manage NuGet Packages The BlueYonder.FlightDetails - Manage NuGet Packages dialog box is displayed.
25. Type EntityFramework in the Search Online combo box.
26. Select the EntityFramework option in the middle pane.
27. Click the Install button. The Installing dialog box is displayed for few seconds and closed automatically.
28 Click the Close button to close BlueYonder.FlightDetails - Manage NuGet Packages dialog box.
29. Right-click the BlueYonder.FlightDetails node in the Solution Explorer window, and then select Set as Startup Project
30. Right-click the BlueYonder.FlightDetails node, and then select Add—Class The Add New Item -BlueYonder.FlightDetails dialog box is displayed.
31. Select and replace the existing text in the Name text box with BlueYonderDbContext
32. Click the Add button. The BlueYonderDbContext.es file is displayed.
33. Type the highlighted portions of the following code snippet in the BlueYonderDbContext.es file:
using System;
using System.Collections.Generic;
using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Data.Entity;
 using BlueYonder.Entities;

34. Type the highlighted portions of the following code snippet in the BlueYonderDbContext.es file:
class BlueYonderDbContext: DbContext
{
public BlueYonderDbContext()
 : base(@"Data
Source= Asqlexpress;Database=BlueYonder .Companion.Lab02integrated Security=True;")
{
}
public DbSet<Location> Locations { get; set; }
public DbSet<Flight> Flights { get; set; }
public DbSet<FlightSchedule> FlightSchedules { get; set; }
public DbSet<Traveler> Travelers { get; set; }
public DbSet<Reservation> Reservations { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<FlightSchedule>()
.HasRequired(fs => fs.Flight)
.WithMany(f => f.Schedules)
.Map(m => m.MapKeyC'FlightlD")); modelBuilder.Entity<Reservation>()
.HasRequired(r => r.DepartureFlight)
.WithManyQ
.HasForeignKey(r => r.DepartFlightSchedulelD); modelBuilder.Entity<Reservation>()
.HasOptional(r => r.ReturnFlight)
.WithManyQ
.HasForeignKey(r => r.ReturnFlightSchedulelD);
}
}
35. Ensure that the Solution Explorer window is opened
36. Double-click the Program.es file.
37. Type the highlighted portions of the following code snippet in the Program.es file:
static void Main(string[] args)
{
BlueYonderDbContext bdbc = new BlueYonderObContext() ;
 Console.WriteLine("Please enter the Flight Number:");
 string flightNumber = Console.ReadLine();
var flightDetails = bdbc.Flights.Where(f => f.FlightNumber == flightNumber) .FirstOrDefault();
if (flightDetails != null)
{
Console.WriteLine("The flight starts from " + flightDetails.Source.Ci ”, " + flightDetails.Source.Country + " for " + flightDetails.Destination.City + ", " flightDetails.Destination.Country + ".");
}
else
{
Console.WriteLine("Invalid Flight Number.");
}
Console.WriteLine("\nPress the ENTER key to close the application.") Console. ReadLineQ;
}
38. Select FILE—Save All to save the changes.
39. Press the F5 key to run the application. The Console window is displayed.
40. Type BY001 in the Console window, and then press the Enter key. The flight details is displayed.
41. Press the Enter key to close the application.
42. Close Microsoft Visual Studio 2012.
Console.WriteLine("Invalid Flight Number.");
}