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.

1 comment:

Bhargavi said...

Hi, Please attach luxury drive database