Likes

Developing Windows Azure and Web Services Lab @ 8 Ans 2

Luxury Drive is using an XML Web service that provides the details about the various models of the cars manufactured by the company. The Web service is used by the company's call center and the distributors. The call center employees use a client application developed in .NET to access the Web service. However, the distributors use various applications having different platfonns to access the Web service. The management at Luxury Drive wants their Web service to be such that it can accommodate features such as reliable messaging, transactions, and security in future. The management has conveyed the same to the developers. The developers know that they can implement all these features in the existing XML Web service. However, it would be difficult because each of these features is provided by different technologies and merging all these technologies is a time-consuming and complex task. Therefore, the developers decided to create the Web service by using WCF because WCF is the unification of all these technologies and provides all the required features. You. as a distributed application developer, have to create a WCF service that provides the details about the various models of the cars manufactured by the company.
Solution



To create the required WCF service, you need to perform the following tasks:
1. Attach the database in the Microsoft SQL Server Management Studio window.
2. Create a WCF service.
3. Verify the WCF service.
Task 1: Attaching the Database in the Microsoft SQL Server Management Studio Window
To attach the database in the Microsoft SQL Server Management Studio window, 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. Open SQL Server Management Studio as administrator. The Connect to Server dialog box is displayed.
4. Type .\sqlexpress in the Server name text box.
5. Select Windows Authentication in the Authentication drop-down list.
6. Click the Connect button. The Microsoft SQL Server Management Studio window is displayed.
7. Right-click the Databases node in the Object Explorer window, and then select the Attach option from the context menu. The Attach Databases dialog box is displayed.
8. Click the Add button.
9. Browse to the location where the Exercise 03.zip file is extracted.
10. Expand the Exercise 03 folder.
11. Expand the Database folder.
12. Select the LuxuryDrive.mdf file.
13. Click the OK button.
14. Click the OK button. The LuxuryDrive database is added in the Databases folder.

Task 2: Creating a WCF Service
To create a WCF Service, you need to perform the following steps:
1. Open Microsoft Visual Studio 2012.
2. Select File—New—Web Site. The New Web Site dialog box is displayed.
3. Ensure that the Installed—Templates nodes are expanded in the left pane.
4. Select the Visual C# node under the Templates node.
5. Select WCF Service from the list of templates displayed in the middle pane.
6. Select the File System option from the Web location drop-down list.
7. Select and replace the text in the text box next to the Web location drop-down list with D:\Exercises\Module 06\Exercise 03\CarDetailsWCF Service.
8. Click the OK button. The Service.cs file is displayed.
9. Type the highlighted portions of the following code snippet in the Service.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
10. Remove the following code snippet from the Service class:
public string GetOata(int value)
{
return string.Format("You entered: (0)", value);
>
public CompositeType GetDataUsingOataContract(CompositeType composite)
{
if (composite «■ null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue +- "Suffix";
>
return composite;
>
11. Type the highlighted portions of the following code snippet in the Service class:
public class Service : IService
{
public DataSet QueryCarModel(string model)
{ SqlConnection conObj = new SqlConnection(@"Data
Source:.\sqlexpress;database=LuxuryDrive;Integrated Securityrtrue;");
SqlDataAdapter daObj = new SqlDataAdapter("SELECT * FROM ModelNo = ," + model + ..., conObj)j
DataSet dsObj = new DataSetQ;
daObj.Fill(dsObj, "CarDetails");
return dsObj;
>
}
12. Ensure that the Solution Explorer window is opened.
13. Expand the App_Code node.
14. Double-click the I Service.cs file. The I Service.cs file is displayed.
15. Type the highlighted portion of the following code snippet in the IService.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
...................
...................
16. Remove the following code snippet from the iservice interface:
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDatal)singDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[OataContract]
public class CompositeType
{
bool boolValue = true; string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; } set { boolValue ■ value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; } set { stringValue = value; >
>
17. Type the highlighted portions of the following code snippet in the iservice interface:
public interface IService
{
[OperationContract]
DataSet QueryCarModel(string model);
>
18. Select FILE— Save All to save the changes.
19. Press the F6 key.
Task 3: Verifying the WCF Service
To verify the WCF service, you need to perform the following steps:
1. Open a new window of Microsoft Visual Studio 2012.
2. Select FILE—Open—Web Site. The Open Web Site dialog box is displayed.
3. Ensure that File System is selected in the left pane of the Open Web Site dialog box.
4. Browse to the location where the Exercise 03.zip file is extracted.
5. Expand the Exercise 03 folder.
6. Select the QueryCarDetailsClientApp folder, which is provided to you by the faculty, from the Select the folder you want to open list box.
7. Click the Open button. The QueryCarDetailsClientApp.sin (2) - Microsoft Visual Studio window is displayed.
8. Switch to the CarDetailsWCF Service (1) - Microsoft Visual Studio window.
9. Ensure that the Solution Explorer window is opened.
10. Ensure that the CarDetailsWCF Service(1) node is expanded.
11. Right-click the Service.svc file, and then select Set As Start Page.
12. Press the F5 key. The Debugging Not Enabled dialog box is displayed.
13. Click the OK button. The WCF Test Client window is displayed.
14. Close the WCF Test Client window.
16.Copy the URL from the address bar. and then close the Internet Explorer window.
17.Switch to the QueryCarDetailsClientApp.sIn (2) - Microsoft Visual Studio window.
18.Select Website—Add Service Reference. The Add Service Reference dialog box is displayed. Paste the copied URL in the Address combo box, and then click the OK button.
19.Click the Make Writeable button, if the Edit of Read-Only File dialog box is displayed.
20.Ensure that the Solution Explorer window is opened.
21.Right-click the QueryCarDetailsPage.aspx file, and then select Set As Start Page.
22.Select FILE—Save All to save the changes. The Save File As dialog box is displayed.
23.Browse to the location where Exercise 03.zip file is extracted.
24.Double-click the Exercise 03 folder.
25.Click the Save button.
26.Press the F5 key.
27.Type M002 in the Enter a Model No text box. and then click the Show Details button. The details of the model M002 appear.
29. Close the Internet Explorer window.
30. Close the Microsoft Visual Studio 2012 windows.

HTML MT Solved


Explain the usage of the <IFRAME> tag in HTML. Also, discuss the various attributes of the <IFRAME> tag.

Ans .The HTML <IFRAME> tag is used to specify an inline frame. It allows you to divide a Web page into sections or frames. Each section can be used to display an individual Web page. Therefore, the <IFRAME> tag is used to embed an HTML Web page within another Web page. The embedded Web page is said to be contained within the other Web page, which is known as the containing page. The following attributes can be used with the <IFRAME> tag:

src: Is used to specify the location or the URL of the Web page to be embedded inside the frame.

name: Is used to assign a name to the frame.

seamless: Is a boolean attribute, which instructs the browser to display the frame as a part of the containing Web page. If this attribute is used, the frame is displayed without scroll bars and border.

srcdoc: Is used to specify an HTML code that defines the content to be displayed inside the frame.

height: Is used to set the height of the frame.

width: Is used to set the width of the frame.


What do you mean by loop constructs? Discuss the various loop constructs in JavaScript.Ans. Loop constructs are used to repeatedly execute one or more lines of code. In JavaScript, the following loop constructs can be used:


while 
do...while
for
The while  loop is used to repeatedly execute a block of statements till a condition evaluates to true. The while statement always checks the condition before executing the statements in the loop. The syntax for the while loop is:

while (expression)
{
statements;
}

The do...while loop construct is similar to the while loop construct. However, the statements within the do...while loop are executed before the condition is checked as compared to the while loop, where the statements within the block are executed after the condition is checked. Therefore, the statements within the do...while loop are executed at least once, in comparison to the while loop, where the statements in the block are not executed when the condition evaluates to false for the very first time. It has the following syntax:

do
{ Statements;
}
while(condition)

The for  loop allows the execution of a block of code depending on the result of the evaluation of the test condition. It has the following syntax:

for (initialize variable; test condition; step value)
{// code block
}


Write the code to retrieve the users' location on the click event of a button by using the getCurrentPosition() method. The location coordinates that are retrieved need to be displayed inside the <P></P> tag. 

Ans. <!DOCTYPE HTML>
<HTML>
<BODY>
<P ID="disp_location">Click here to know your location coordinates:</P>
<BUTTON onclick="getLocation()">Get Location</Button>
<SCRIPT>
var geo=document.getElementById("disp_location");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(getPosition);
    }
  else{geo.innerHTML="Geolocation is not supported by this browser.";}
  }
function getPosition(position)
  {
  geo.innerHTML="Latitude: " + position.coords.latitude +
  "<BR>Longitude: " + position.coords.longitude;
  }
</SCRIPT>
</BODY>
</HTML>

What is a function? How can you create a function in JavaScript?

Ans. A function is a self-contained block of statements that has a name and is defined to perform a specific task. A function can be defined once but can be executed repeatedly. Functions can either be built-in or user-defined.

In JavaScript, functions can be created by using the keyword, function, followed by the function name and the parentheses, ().A function can optionally accept a list of parameters. The parameters that a function accepts are provided in parentheses and separated by commas. The function can use the values passed in these parameters to perform certain operations. The following syntax is used to create functions:

function [functionName] (Variable1, Variable2)
{
//function statements
}

Write the JavaScript code to create a clock that updates every one second to display the current time inside a <DIV> element on the Web page.

Ans. <!DOCTYPE HTML>
<HTML>
<HEAD>
<SCxRIPT type="text/javascript">
function clockTime()
{
var todayDate=new Date();
var hrs=todayDate.getHours();
var mns=todayDate.getMinutes();
var scs=todayDate.getSeconds();
mns=check(mns);
scs=check(scs);
document.getElementById('displayTime').innerHTML=hrs+":"+mns+":"+scs;
t=setTimeout('clockTime()',1000);
}

function check(t)
{
if (t<10)
 {
 t="0" + t;
 }
return t;
}
</SCRIPT>
</HEAD>
<BODY onload="clockTime()">
<DIV ID="displayTime"></DIV>
</BODY>
</HTML>

Define canvas. Also, discuss how can you create a canvas and use it for drawing graphic objects in HTML.Ans. A canvas is an area on a Web page that acts as a container for embedding graphic objects. It allows dynamic rendering of bitmap images and 2D shapes by using JavaScript. To create a canvas and use it for drawing, you need to perform the following tasks:


1. Define the canvas
2. Access the canvas

A canvas is defined by using the <CANVAS> tag in the body section of the HTML document. Its important attributes are height, width, style, and ID. You can define a canvas by using the following code within the <BODY> tag:

<CANVAS ID="myCanvas" width="300" height="300" style="border:1px solid black">
</CANVAS>

To actually draw graphic objects on the canvas, you need to access the canvas in the JavaScript code. You can write the following code in the <BODY> tag to access the canvas that you have defined earlier:

<SCRIPT>
var c=document.getElementByID("myCanvas");
var ctx=c.getContext("2d");
</SCRIPT>

Write a code to create a table in HTML, as shown in the following figure.

Ans. <!DOCTYPE HTML><HTML>
<BODY>
<TABLE border = "1">
<THEAD>
<TR><TH colspan= "4">Sales Record</TH></TR>
<TR> <TH> Product ID </TH> <TH> Description</TH> <TH> Quantity</TH><TH> Price</TH></TR>
</THEAD>
<TFOOT>
<TR><TD colspan= "3"> Total price </TD> <TD>$12</TD></TR>
</TFOOT>
<TBODY>
<TR><TD>101</TD><TD>Notebook</TD><TD>50</TD><TD>$5</TD></TR>
<TR><TD>121</TD><TD>Pen</TD><TD>100</TD><TD>$7</TD></TR>
</TBODY>
</TABLE>
</BODY>
</HTML>

What do you understand by preloading the images associated with a Web page? How is preloading of images implemented in JavaScript?

Ans. Preloading images is a technique to load images in the browser cache before the script on the Web page is executed and the Web page is rendered in the browser window. This helps to avoid any delay in loading images from their respective locations, and then displaying these images on the Web page.

The Image object can be used to preload images in an application. To use the Image object, an instance of the Image object needs to be created and the actual images need to be attached to the Image object in the head section. It ensures that the images are loaded in memory before the body of the page gets loaded. The following syntax is used to create an instance of the Image object:

var Imagename= new Image([Width], [Height]);

After instantiating an image object, you need to associate the image with the Image object. For this, the src attribute of the Image object is used as shown in the following code:
  
   Imagename.src="ImageURL",

where, ImageURL is the URL of the image.

What is the use of the <FIELDSET> tag in HTML? Also, briefly discuss the tags and attributes associated with the <FIELDSET> tag.

Ans. The <FIELDSET> tag is used to combine and group related fields in a form. It creates a box around the selected fields.

The <LEGEND> tag is used along with the <FIELDSET> tag to define a caption for the fieldset. It is the simplest way of organizing form elements along with their description in such a way that it is easier for a user to understand.

The <FIELDSET> tag can have the following attributes:

disabled: The disabled attribute is used to indicate that a group of fields should be shown disabled when the page loads.
form: The form attribute is used to specify the name of one or more forms to which the <FIELDSET> tag belongs.
name: The name attribute is used to specify the name for the fieldset.

 Write the code to create a canvas of desired dimension on a Web page and then draw a circle inside it. In addition, you need to apply a radial gradient comprising any four colors on the circle drawn on the canvas.

Ans. <!DOCTYPE HTML>
<HTML>   <BODY>
<CANVAS ID="myCanvas" width="300" height="300" style="border:1px solid black">
</CANVAS>
<SCRIPT>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var grad=ctx.createRadialGradient(75,50,5,90,60,100);
grad.addColorStop(0.2,"orange");
grad.addColorStop(0.4,"green");
grad.addColorStop(0.6,"yellow");
grad.addColorStop(0.8,"red");
ctx.fillStyle=grad;
ctx.beginPath();
ctx.arc(80, 90, 50, 0, Math.PI*2, false);
ctx.fill();
ctx.closePath();
</SCRIPT>
</BODY>
</HTML>

DSA MT SOLVED

Q Explain queue with the help of an example. What are the types of operations that can be performed on a queue? How can you represent a queue in the form of a linked list? 


Ans
A queue is a list of elements in which items are inserted at one end of the queue and deleted from the other end of the queue. You can think of a queue as an open ended pipe, with elements being pushed from one end and coming out of another. The end at which elements are inserted is called the rear, and the end from which the elements are deleted is called the front. A queue is also called a First-In-First-Out (FIFO) list because the first element to be inserted in the queue is the first one to be deleted. The queue data structure is similar to the queues in real life.
The following two types of operations can be performed on queues:
•Insert: It refers to the addition of an item in the queue. Items are always inserted at the rear end of the queue.
•Delete: It refers to the deletion of an item from a queue. Items are always deleted from the front of the queue. When an item is deleted, the next item in the sequence becomes the front end of the queue.


class Node
{
public int data; public Node next;
}
class LinkedQueue
{
Node FRONT, REAR;
public LinkedQueue()
{
FRONT = null;
REAR = null;
}
public void insert (int element)
{
}
public void remove()
{
}
public void display()
{
}
}

Q Peter has been assigned a task to develop a code to implement a delete operation on a binary search tree. However, before doing so, he first needs to write a code to locate the position of the node to be deleted and its parent. To do so, he has written the following algorithm:
1. Make a variable/pointer currentNode point to the root node.2. Make a variable/pointer parent point to root.3. Repeat the steps, a, b, and c until currentNode becomes NULL or the value of the    node to be searched becomes greater than currentNode:    a. Make parent point to currentNode.    b. If the value to be deleted is greater than that of currentNode:         i. Make currentNode point to its left child.    c. If the value to be deleted is less than that of currentNode:         i. Make currentNode point to its right child.
However, the preceding algorithm does not give the desired output. Write the correct algorithm.


Ans
1. Make a variable/pointer currentNode point to the root node.
2. Make a variable/pointer parent point to NULL.
3. Repeat the steps, a, b, and c until currentNode becomes NULL or the value of the
    node to be searched becomes equal to that of currentNode:
    a. Make parent point to currentNode.
    b. If the value to be deleted is less than that of currentNode:
         i. Make currentNode point to its left child.
    c. If the value to be deleted is greater than that of currentNode:         
         i. Make currentNode point to its right child.

 Q.How can you represent a stack by using a linked list?Ans...


 Code in C#
class Node {
       public int info;
        public Node next;
public Node(int i, Node n)
{         
  info = i;
  next = n;
}}

After representing a node of a stack, you need to declare a class to implement operations on a stack. In this class, you also need to declare a variable/pointer to hold the address of the topmost element in the stack and initialize this variable/pointer to contain the value, NULL.
class Stack
   {   
    Node top;   
    public Stack() 
      {    
       top = null;
       }
       bool empty()
   {            // Statements        }
      public void push(int element)
        {            // Statements        }  
     public void pop()     
  {             // Statements        }}

After declaring the class to implement the operations on the stack, you need to implement the PUSH and POP operations.

Q. Define the following terms:a.    Edgeb.    Depth  of a treec.    Leaf noded.    Degree of a nodee.    Children of a node


Ans..
    Edge:  A link from a parent to a child node is known as an edge.
b.    Depth of a tree:  The maximum number of levels in a tree is called the depth of
       a tree.
c.    Leaf node: A node with no children is called a leaf node.
d.    Degree of a node: The number of sub trees of a node is called the degree of a
       node.
e.    Children of a node: The roots of the sub trees of a node are called the children of
       the node.


Q.  Explain stack with the help of an example. What are the characteristics of a stack? Briefly explain the operations that can be performed on a stack?


Ans.
A stack is a collection of data items that can be accessed at only one end, which is called top. This means that the items are inserted and deleted at the top. The last item that is inserted in a stack is the first one to be deleted. Therefore, a stack is called a Last-In-First-Out (LIFO) data structure.
A stack is like an empty box containing books, which is just wide enough to hold the books in one pile. The books can be placed, as well as removed, only from the top of the box. The book most recently put in the box is the first one to be taken out. The book at the bottom is the first one to be put inside the box and the last one to be taken out.
The characteristics of stacks are:
1.  Data can only be inserted on the top of the stack.
2.  Data can only be deleted from the top of the stack.
3.  Data cannot be deleted from the middle of the stack. All the items from the top
     first need to be removed.  
The following two basic operations can be performed on a stack:
1.  PUSH
2.  POP
When you insert an item into a stack, you say that you have pushed the item into the stack. When you delete an item from a stack, you say that you have popped the item from the stack.


Q. John has been assigned a task to develop a code to implement preorder traversal of a binary tree. He has developed the code according to the following algorithm:preorder (root)1. If (root = NULL):        a. Exit.2. preorder (left child of root).3. Visit (root).4. preorder (right child of root).

 Analyze the algorithm and check if the same will execute as expected. Suggest changes, if required. Also, write the algorithm for postorder traversal of a binary tree.


Ans.
The given algorithm is incorrect. The algorithm for preorder traversal of tree is:
preorder (root)
1. If (root = NULL):   
     a. Exit.
2. Visit (root).
3. preorder (left child of root).
4. preorder (right child of root).

The algorithm for postorder traversal of a tree is:
postorder (root)
1. If (root = NULL):   
     a. Exit.
2. postorder (left child of root).
3. postorder (right child of root).
4. Visit (root).

Q.  Explain stack with the help of an example. What are the characteristics of a stack? Briefly explain the operations that can be performed on a stack?


Ans.
A stack is a collection of data items that can be accessed at only one end, which is called top. This means that the items are inserted and deleted at the top. The last item that is inserted in a stack is the first one to be deleted. Therefore, a stack is called a Last-In-First-Out (LIFO) data structure.
A stack is like an empty box containing books, which is just wide enough to hold the books in one pile. The books can be placed, as well as removed, only from the top of the box. The book most recently put in the box is the first one to be taken out. The book at the bottom is the first one to be put inside the box and the last one to be taken out.
The characteristics of stacks are:
1.  Data can only be inserted on the top of the stack.
2.  Data can only be deleted from the top of the stack.
3.  Data cannot be deleted from the middle of the stack. All the items from the top
     first need to be removed.  
The following two basic operations can be performed on a stack:
1.  PUSH
2.  POP
When you insert an item into a stack, you say that you have pushed the item into the stack. When you delete an item from a stack, you say that you have popped the item from the stack.

Q.  Explain briefly how can you represent a binary tree?
Ans..

To represent a binary tree, you need to declare two classes:
•A class to represent a node of the tree: This class represents the structure of each node in a binary tree. A node in a binary tree consists of the following parts:
?Information: It refers to the information held by each node in a binary tree.
?Left child: It holds the reference of the left child of the node.
?Right child: It holds the reference of the right child of the node.


•A Class to represent the binary tree: This class implements various operations on a binary tree, such as insert, delete, and traverse. The class also provides the declaration of the variable/pointer root, which contains the address of the root node of the tree.

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.