Likes

Developing Windows Azure and Web Services Lab @ 8 Ans 1

The second step in creating the WCF service is to create a project for hosting the service. In this exercise you will create a service host, configure it with a TCP endpoint and use it to make the service available for clients.
The main tasks for this exercise are:
1. Create a console project to host the WCF service.
2. Configure the service to use a TCP endpoint.
3. Create the service hosting code.

Solution


Task 1: Creating a Console Project to Host the WCF Service
To create a console project to host the WCF service, 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. Double-click the Exercise 02 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. Select FILE—Add—New Project. The Add New Project dialog box is displayed.
7. Select the Windows node under the Visual C# node in the left pane.
8. Select Console Application from the list of templates displayed in the middle pane.
9. Select and replace the text in the Name text box with BlueYonder.Booking Service.Host.
10. Click the OK button.
11. Ensure that the Solution Explorer window is opened.
12. Right-click the BlueYonder.Booking Service.Host node, and then select Add Reference. The Reference Manager -BlueYonder.Booking Service.Host dailog box is displayed.
13. Ensure that Framework is selected under the Assemblies node in the left pane.
14. Scroll down and select the check box next to the System.ServiceModel assembly in the middle pane.
15. Click the Solution node in the left pane.
16. Select the check boxes next to the following project names in the middle pane:
* BlueYonder.Booking Service.Contracts
o BlueYonder.Booking Service.lmplementation
o BlueYonder.DataAccess o BlueYonder.Entities
17. Click the OK button.
18. Ensure that the Solution Explorer window is opened.
19. Right-click the BlueYonder.Booking Service.Host node, and then select Manage NuGet Packages. The BlueYonder.Booking Service.Host - Manage NuGet Packages dialog box is displayed.
20. Click the Online node in the left pane.
21. Type EntityFramework in the search box on the top-right corner.
22. Select EntityFramework in the middle pane, and then click the Install button.
23. Click the I Accept button, if the License Acceptance dialog box is displayed.
24. Click the Close button.
25. Ensure that the Solution Explorer window is opened.
26. Right-click the BlueYonder.Booking Service.Host node, and then select Add—Existing Item. The Add Existing Item -BlueYonder.BookingService.Host dialog box is displayed.
27. Browse to the location where the Exercise 02.zip file is extracted.
28. Double-click the Exercise 02 folder.
29. Double-click the Assets folder.
30. Select the FlightScheduleDatabaselnitializer.es file.
31. Click the Add button
32. Select FILE— Save All to save the changes.

Task 2: Configuring the Service to Use a TCP Endpoint

To configure the service to use a TCP endpoint, you need to perform the following steps:
1. Ensure that Solution Explorer window is opened.
2. Ensure that the BlueYonder.Booking Service.Host node is expanded.
3. Double-click the App.config file. The App.config file is displayed.
4. Type the highlighted portions of the following code snippet in the App.config file:

<?xml version="l.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /'. </startup>
<system.serviceModel>
<services>
<service name="BlueYonder.BookingService.Implementation.BookingSei <endpoint name="BookingTcp" addresss"net.tcp://localhost/BlueYoi binding="netTcpBinding" contract="BlueYonder.BookingService.Contracts.Ii </service>
</services>
</system.serviceModel>
<connectionStrings>
<add name="BlueYonderServer" connectionString="Data Sources.\SQLEXPRESS$Database=BlueYonder.Server.Lab5;Integrated Security: providerName="System.Data.SqlClient" />
</connectionStrings>
5. Select FILE— Save All to save the changes.

Task 3: Creating the Service Hosting Code
To create the service hosting code, you need to perform the following steps:
1. Ensure that Solution Explorer window is opened.
2. Ensure that the BlueYonder.Booking Service.Host node is expanded.
3. Double-click the Program.es file. The Program.es file is dispalyed.
4. Type the highlighted portions of the following code snippet in the Program.es file:
using System;
using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ServiceModel; using BlueYonder.DataAccess;
namespace BlueYonder.BookingService.Host
{
class Program
{
static void Main(string[] args)
{
}
private static void OnServiceOpened(object sender, EventArgs e)
{
Console.WriteLine('*Booking Service Is Running... Press [ENTER] to close.
>
private static void OnServiceOpening(object sender, EventArgs e)
{
Console.WriteLine(”Booking Service Is Initializing...");
}
>
>
5. Add the following code snippet inside the Main() method of the Program.es file:
van dblnitializer = new FlightScheduleDatabaselnitializer();
dblnitializer.InitializeDatabase(new TravelCompanionContext(Implementation.BookingService.ConnectionName));
van host = new ServiceHost(typeof(Implementation.BookingServ host.Opening += OnServiceOpening; host.Opened += OnServiceOpened; try {
host.Open();
>
catch (Exception e)
{
host = null;
Console.WriteLine(" *** Error occured while trying to service host *** \n\n{0}", e.Message);
Console.WriteLine("\n\n Press [ENTER] to exit.");
>
Console.ReadLine(); if (host == null) return; try {
host. Close();
}
catch (Exception)
{
host.Abort();
}
6. Select FILE—Save All to save the changes.
7. Right-click the BlueYonder.BookingService.Host node, and then select Set as Startup Project.
8. Press the F5 key. The Console window is displayed.
9. Click the Allow access button, if the Windows Security Alert dialog box is displayed.
10. Close the Console window.
11. Switch to Microsoft Visual Studio 2012, and close it.

Developing Windows Azure and Web Services Lab @ 7 Ans 2

The first step in creating a WCF service is to define the service contract and data contracts. Only afterwards you can begin implementing the service contract. In this exercise, you will define a service contract interface 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 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 Bockingservice 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. SaveQ; 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 @ 7 Ans 1

To support secured communication between the service and the client you will need to define a certificate.
You need to add to the service support for HTTPS binding that uses a certificate and set the client to work with the secured connection.
The main tasks for this exercise are:
1. Add an HTTPS binding in IIS.
2. Host ASP.NET Web API Web application in IIS.
3. Change the addresses of the service used in the client application and run the client application.




To implement the required functionality, you need to perform the following steps:
1. Browse to the location where the Exercise 05.zip file is saved.
2. Extract the Exercise 05.zip file.
3. Double-click the Exercise 05 folder.
4. Press the Window logo key. The Start screen is displayed.
5. Start hyping Internet Information Services.
6. Click the Internet Information Services (IIS) Manager tile. The Internet Information Services (IIS) Manager window is displayed.
7. Click the No button, if the Internet Information Services (IIS) Manager dialog box is displayed.
8. Double-click the Server Certificates icon under the IIS group in the middle pane.
9. Click the Create Self-Signed Certificate link in the Actions pane. The Create Self-Signed Certificate dialog box is displayed.
10. Type BlueYonderAirlinesRootCA in the Specify a friendly name for the certificate text box.
11. Select the Web Hosting option from the Select a certificate store for the new certificate drop-down list.
12. Click the OK button.
13. Expand the node in the Connections pane that has same name as your machine name.
14. Expand the Sites node.
15. Select the Default Web Site node.
16. Click the Bindings link in the Actions pane. The Site Bindings dialog box is displayed.
17. Click the Add button. The Add Site Binding dialog box is displayed.
18. Select the https option from the Type drop-down list.
19. Type localhost in the Host name text box.
20. Select the BlueYonderAirlinesRootCA option from the SSL certificate drop-down list.
21. Click the OK button. An HTTPS binding is added to the Site Binding list.
22. Click the Close button to close the Site Bindings dialog box. When you add HTTPS binding to the Site Binding, all Web applications that are configured with HTTP binding will support HTTPS.
23. Open Microsoft Visual Studio 2012 as administrator.
24. Select FILE—Open—Project-Solution. The Open Project dialog box is displayed.
25. Browse to the location where the Exercise 05.zip file is extracted.
26. Double-click the Exercise 05 folder.
27. Double-click the BlueYonder.Companion folder.
28. Select the BlueYonder.Companion.sln file.
29. Click the Open button. The BlueYonder.Companion - Microsoft Visual Studio (Administrator) window is displayed.
30. Ensure that the Solution Explorer window is opened.
31. Ensure that the BlueYonder.Companion.Host node is expanded.
32. Double-click the Web.config file. The Web.config file is displayed.
33. Locate and replace the string user id=BlueYonder;Password=Pa$$werd; with user id=sa;Password=passwcrdSl23;.
34. Select BUILD—Batch Build. The Batch Build dialog box is displayed.
35. Click the Select All button.
36. Click the Clean button. The Batch Build dialog box is closed automatically.
37. Select BUILD—Batch Build. The Batch Build dialog box is displayed.
38. Ensure that all the check boxes are selected under the Build column.
39. Click the Build button. The Batch Build dialog box is closed automatically.
Note: If errors or warnings are displayed in the build process, right-click the root solution node and then select Manage NuGet Packages for Solution.
Further, click the Restore button in the popup that appears at the top of the dialog box displayed. Once all the references are restored, close the dialog box and repeat the build process.
40. Ensure that the Solution Explorer window is opened.
41. Right-click the BlueYonder.Companion.Host node, and then select Properties The BlueYonder.Companion.Host window is displayed.
42. Select Web in the left pane.
43. Clear the Use IIS Express check box.
44. Click the Create Virtual Directory button. If the Microsoft Visual Studio dialog box appears, click the Yes button.
45. Click the OK button when the confirmation message box is displayed.
46. Select FILE—Save All to save the changes.
47. Switch to the Internet Information Services (IIS) Manager window.
48. Right-click the Default Web Site node, and then select Refresh.
49. Expand the Default Web Site node.
50. Click the BlueYonder.Companion.Host node.
51. Click the Browse '.80 (http) link in the Actions pane. The Internet Explorer window is displayed.
52. Append locations to the address in the address bar. and then press the Enter key. A prompt at the bottom of the Internet Explorer window is displayed.
53. Click the Open button.
54. Select Notepad from the list of available programs, if you are prompted to select a program to open the file. The locations.json file is displayed.
55. Close the locations.json file.
56. Replace the address available in the address bar of the Internet Explorer window with https://localhost/BlueYonder.Companion.Host-locations. and then press the Enter key.
57. Click the Continue to this website (not recommended), link, if you get a message There is a problem with this website's security certificate. A prompt at the bottom of the Internet Explorer window is displayed.
58. Click the Open button.
59. Select Notepad from the list of available programs if you are prompted to select a program to open the file. The locations.json file is displayed.
60. Explore the contents of the file. It contains data of the Location table.
61. Close the locations.json file.
62. Close the Internet Information Services (IIS) Manager window.
63. Close the Internet Explorer window.
64. Switch to Microsoft Visual Studio 2012, and close it.

Developing Windows Azure and Web Services Lab @ 6 Ans 2

To make your web application more robust, you need to add some validations to the incoming data. You will apply validation rule to your server to verify that all required fields of a model are sent from the client before handling the request. You will decorate the Travel model with attributes that define the required fields, then you will derive from the ActionFilter class and implement the validation of the model. Finally, you will add the validation to the Post action.
The main tasks for this exercise are:
1. Add data annotations to the Traveler class.
2. Create a class that derives from ActionFilterAttribute.
3. Implement the action filter to validate the model.
4. Add a custom attribute to the put and post actions in the booking service.




To implement the required functionality, you need to perform the following steps:
1. Browse to the location where the Exercise 04.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 theVisual 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 04.zip file is extracted.
9. Double-click the Exercise 04 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 (Administrator) window is displayed.
13. Ensure that the Solution Explorer window is opened.
14. Expand the BlueYonder.Entities node.
15. Double-click the Traveler.es file. The Traveler.es file is displayed.
16. Type the highlighted portions of the following code snippet in the Traveler.es file:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
namespace BlueYonder.Entities
{
public class Traveler
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Travelerld { get; set; }
public string TravelerUserldentity { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Phone]
public string MobilePhone { get; set; }
[Required]
public string HomeAddress { get; set; }
public string Passport { get; set; }
[EmailAddress]
public string Email { get; set; }
>
}
17. Select FILE—Save All to save the changes.
18. Right-click the BlueYonder.Companion.Controllers project in the Solution Explorer window, and then select Add—New Folder.
19. Type ActionFilters. and then press the Enter key.
20. Right-click the ActionFilters folder, and then select Add—Class. The Add New Item -BlueYonder.Companion.Controllers dialog box is displayed.
21. Select and replace the existing text in the Name text box with ModelValidationAttribute.
22. Click the Add button. The ModelValidationAttribute.es file is displayed.
23. Type the highlighted portions of the following code snippet in the ModelValidationAttribute.es file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.Filters;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace BlueYonder.Companion.Controllers.ActionFilters
{
public class ModelValidationAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(
System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (!actionContext.ModclStatc.IsValid)
actionContext.Response = actionContext.Request.CreateErrorRespons HttpStatusCode.BadRequest, new HttpError(actionContext.ModelState, true));
>
}
}
24. Select FILE— Save All to save the changes.
25. Ensure that the BlueYonder.Companion.Controllers node is expanded in the Solution Explorer window.
26. Double-click the TravelersController.es file. The TravelersController.es file is displayed.
27. Type the highlighted portion of the following code snippet in the TravelersController.es file:
using BlueYonder.Companion.Entities; using BlueYonder.DataAccess.Repositories; using BlueYonde r.Companion.Controlle rs.ActionF ilters; namespace BlueYonder.Companion.Controllers
28. Type the highlighted portion of the following code snippet in the TravelersController.es file: public HttpResponseMessage Get(string id)
{
var traveler = Travelers.FindBy( t -> t .Travelerllserldentity -- id) . FirstOrDefaultQ;
// Handling the HTTP status codes
if (traveler != null)
return Request.CreateResponse<Traveler>
(HttpStatusCode.OK, traveler); else
return Request.CreateResponse(HttpStatusCode.NotFound);
}
[ModelValidation]
public HttpResponseMessage Post(Traveler traveler)
{
// saving the new order to the database Travelers.Add(traveler);
Travelers.Save();
// creating the response, with three key features:
// 1. the newly saved entity // 2. 201 Created status code
// 3. Location header with the location of the new resource var response ■ Request.CreateResponse(HttpStatusCode.Created, traveler); response.Headers.Location = new Uri(Request.RequestUri, traveler.Traveler ToStringQ);
return response;
}
[ModelValidation]
public HttpResponseMessage Put(int id, [FromBody]Traveler traveler)
{
// returning 404 if the entity doesn't exist if (Travelers.GetSingle(id) == null)
return Request.CreateResponse(HttpStatusCode.NotFound);
T ravelers.Edit(traveler);
T ravelers.Save();
return Request.CreateResponse(HttpStatusCode.OK);
}
29. Select FILE—Save All to save the changes.
30. Select BUILD—Build Solution. The Build succeeded message is displayed on the status bar at the bottom of the BlueYonder.Companion - Microsoft Visual Studio (Administrator) window.
31. Close Microsoft Visual Studio 2012.

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.");
}