Share via


Readme

patterns & practices Developer Center

On this page: Download:
Example Summary | About the Example Solution | Before You Start | Set Up Your Development Computer and Build the Solution | Create the Adventure Works Database | (Optional) Configure the UI Web Application | Supported Scenarios | To Run the Default Solution on Your Development Computer using Visual Studio LocalDB and the In-Memory Data Stores | To Run the Solution using Windows Azure SQL Database to Store Customer and Order Information | To Run the Solution using Windows Azure Table Service to Store Shopping Cart Information | To Run the Solution using MongoDB to Store Product Information | To Run the Solution using MongoDB to Order History Information | To Run the Solution using Neo4j to Store Product Recommendations | To Run the Solution using Windows Azure Blob Service to Store Product Images | To Run the Solution using Windows Azure Table Service, MongoDB, and Neo4j NoSQL Databases, and Blob Service | Configure the Application | To Configure the MvcWebApi Web Service to Store Shopping Cart Information in the Windows Azure Table Service | To Configure the MvcWebApi Web Service to Store Product Information in MongoDB | To Configure the MvcWebApi Web Service to Store Order History Information in MongoDB | To Configure the MvcWebApi Web Service to Store Product Recommendation Information in Neo4j | To Configure the User Interface to Download Product Images from Windows Azure Blob Service | Check the Sample Functionality

Download code samples

Download PDF

Order Paperback

Example Summary

This document describes how to configure the Visual Studio example solution that accompanies the guide Building Highly-Scalable Solutions for Storing and Retrieving Data Using SQL and NoSQL Databases. This guide focuses on the common issues that you may encounter when building applications that need to store data in a variety of different data stores, such as a relational database, a key-value store, a document database, or a graph database.

This document contains the following sections:

  • About the Example Solution describes the high level structure of the sample application.
  • Before You Start describes the procedures that you must follow before configuring and running the application.
  • Supported Scenarios describes how to build and run the application in each of the scenarios described in the guide.
  • Configure the Application describes how to modify the configuration to support each of the scenarios described in the guide.
  • Check the Sample Functionality describes how to verify that the application is running correctly.

About the Example Solution

The example solution implements a shopping application that enables customers to browse products and place orders. The application runs by using the web. Orders are handled by a separate order service, and for completeness the example solution includes a simulation of this order service.

The Shopping application is a polyglot system that stores the data it uses in a variety of different repositories. Each repository was selected to meet the business requirements of a specific scenario in the application:

  • Customer information is stored in a relational database.
  • Shopping cart information is stored in a key/value store.
  • Product information is stored in a document database.
  • Active order information is stored in a relational database.
  • Order history information is stored in a document database.
  • Product recommendations are stored in a graph database.

Note

The accompanying guide describes the rationale behind choosing these technologies.

There are two versions of the example solution:

  • The dag.sln solution, which contains an ASP.Net web application and an ASP.NET Web API web service. The web application (UI.Mvc) provides the user interface and the web service (DataAccess.MvcWebApi) provides the data access functionality. The simulated order service runs as an asynchronous task invoked by the web service.
  • The dag.azure.sln solution, which contains Windows Azure web roles. The first web role hosts the user interface (UI.Mvc) and the second hosts the web service (DataAccess.MvcWebApi). By default these roles run in the local development fabric, but if you have a valid Windows Azure subscription you can deploy the web roles to the cloud.

The default configuration of both versions of the solution use Visual Studio LocalDB to provide the relational database, and creates simulated in-memory NoSQL data stores to provide the key/value, document, and graph databases. The default solution also uses the task-based version of the orders service. However, you can configure the application in the following ways:

  • Use SQL Server 2012 running on your own computer to hold customer and order information.

  • Use Windows Azure SQL Database to store customer and order information in the cloud (this configuration is necessary if you wish to deploy the web roles in the dag.azure solution to the cloud).

  • Use Windows Azure Table service (either in the local development fabric or in the cloud) to store shopping cart information.

    Note

    To use Azure Table Storage, you should use the dag.azure.sln.

  • Use MongoDB to store product information.

  • Use MongoDB to store order history information.

  • Use Neo4J to store product recommendations.

Note

If you deploy the Windows Azure web roles to the cloud and you wish to use MonogDB and/or Neo4j to provide the NoSQL databases rather than use the simulated in-memory stores, you will need to open up access to the computers hosting these databases to the cloud.

The following schematic illustrates the high level architecture of the Shopping application. The accompanying guide describes the structure of the solution in more detail.

Dn313286.73986A3486555A55ADB219E3BE17D37A(en-us,PandP.10).png

Before You Start

This section describes the procedures that you must follow before configuring and running the application.

Set Up Your Development Computer and Build the Solution

  1. Make sure that you have installed the prerequisite software listed in the release notes.
  2. Start Visual Studio as an administrator and open one of the following solutions:
    1. If you want to use the version of the application that runs as an ASP.NET web application and ASP.NET Web API web service then open the dag.sln solution.

      Note

      You need to set both DataAccess.MvcWebApi and UI.Mvc as the startup projects. To do that, right click onSolution and selectSet StartUp Projects…,select Multiple startup projects:, and then change the dropdown for DataAccess.MvcWebApi and UI.Mvc from None to Start.

    2. If you want to use the version of the application that runs as Windows Azure web roles then open the dag.azure.sln solution.

  3. On the Build menu, click Build Solution.
  4. Verify that the solution builds without any errors.

Create the Adventure Works Database

Note

You can also run the solution by using SQL Server rather than Visual Studio LocalDB. In the instructions that follow, replace the instance (localdb)\v11.0 with the instance of SQL Server that you are using to store the database.
If you wish to use Windows Azure SQL Database, omit this step and instead follow the instructions in the section To Run the Solution using Windows Azure SQL Database to Store Customer and Order Information later in this document.

  1. Install the AdventureWorks2012 OLTP Database on your computer:

    1. Download the AdventureWorks2012 Data File from http://msftdbprodsamples.codeplex.com/releases/view/55330.

    2. In Visual Studio 2012, on the SQL menu, point to Transact-SQL Editor and then click New Query.

    3. Connect to the local development version of SQL Server Express running on your computer, (localdb)\v11.0, by using Windows Authentication.

    4. In the Transact-SQL-Editor enter the following SQL statement. Replace {drive} and {file path} with the drive name and folder name where you saved the AdventureWorks2012 data file:

      CREATE DATABASE AdventureWorks2012 ON (FILENAME = '{drive}:\{file path}\AdventureWorks2012_Data.mdf') FOR ATTACH_REBUILD_LOG;
      
    5. Press Ctrl+Shift+E to run the statement.

      Note

      Whenyou run this command, you may see messages similar to these:
      File activation failure. The physical file name "C:\AdventureWorks\AdventureWorks2012_log.ldf" may be incorrect.
      New log file 'C\AdventureWorks\AdventureWorks2012_log.ldf' was created.
      Convertingdatabase'AdventureWorks2012'fromversion705tothecurrentversion706.
      Database 'AdventureWorks2012' running the upgrade step from version 705 to version 706.
      You can safely ignore these messages.

  2. Update the SalesOrderHeader and Person tables to include additional information required by the example solution:

    1. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command:

      .\SetupDataGuidance.ps1 –createSqlTrackingId $true –createSqlPersonGuid $true –sqlConnectionString "Data Source=(localdb)\v11.0;Initial Catalog=AdventureWorks2012; Integrated Security=SSPI"
      
    2. Verify that the script completes without any errors.

(Optional) Configure the UI Web Application

Note

The sample solution assumes that the UI web application and the Adventure WorksASP.NETWeb API web service are both running on the same computer. If they are running on different computers, you must modify the web.config file of the UI web application and the web service as follows:

  1. Modify the web.config file of the web service to allow cross origin requests from the UI web application:
    1. In Visual Studio 2012, in the dag or dag.azure solution, in the ServicesImplementation folder, in the DataAccess.MvcWebApi project, double-click****the web.config file.
    2. In the <appSettings> section find the setting with the key of CORSHandlerAllowedHosts.
    3. Change the value of the CORSHandlerAllowedHosts setting and replace the IP address 127.0.0.1 and localhost alias with the IP address and name of the computer hosting the UI web application.
    4. Save the web.config file.
  2. Modify the web.config file of the UI web application to send requests to the computer hosting the web server:
    1. In the dag or dag.azure solution, in the UI folder, in the UI.Mvc project, open the web.config file.

    2. Find the <appSettings> section.

    3. Change the value of the baseApiUrl setting and replace the IP address 127.0.0.1 with the IP address of the computer hosting the web service.

      Note

      The web service listens for requests on port 12345. Do not change this port number in the URL.

    4. Save the web.config file.

Supported Scenarios

This section describes how to build and run the application in each of the scenarios described in the guide.

To Run the Default Solution on Your Development Computer using Visual Studio LocalDB and the In-Memory Data Stores

To run the default solution that uses Visual Studio LocalDB and the simulated in-memory databases to store the data on your development computer, step through the following procedures in the order shown to perform the required tasks:

  1. Ensure that you have installed and configured the application and dependent software as described in the sections Set Up Your Development Computer and Build the Solution and Create the Adventure Works Database earlier in this document. Additionally, if the UI web application and the Adventure Works ASP.NET Web API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.
  2. Build and run the solution.
  3. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

To Run the Solution using Windows Azure SQL Database to Store Customer and Order Information

To run the default solution to use Windows Azure SQL Database in the cloud, step through the following procedures in the order shown to perform the required tasks:

  1. Ensure that you have installed and configured the application and dependent software as described in the section Set Up Your Development Computer and Build the Solution earlier in this document. Additionally, if the UI web application and the Adventure Works ASP.NET Web API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.

  2. Create a new Windows Azure SQL Database:

    1. Using Internet Explorer, log in to your Windows Azure subscription at https://manage.windowsazure.com.

    2. In the navigation pane on the left-hand side of the page, click SQL Databases.

    3. In the toolbar at the bottom of the page, click New and then click Custom Create.

    4. In the Name box type AdventureWorks2012, in the Server drop-down list box click New SQL database server, leave the remaining options at their default value, and then click Next.

    5. Specify a login name and password, select a region to host the database server, and then click Complete.

    6. In the SQL Databases pane, make a note of the name of the database server.

    7. In the list of databases, click the arrow in the Name column for the AdventureWorks2012 database.

    8. Under Design your SQL Database, click Set up Windows Azure firewall rules for this IP address.

    9. In the message bar displaying the message The current IP address xx.xx.xx.xx is not included in existing firewall rules. Do you want to update the firewall rules? click Yes.

      Note

      If you do not update the firewall rules, you will not be able to connect to the database from your computer.

  3. Create the tables for the AdventureWorks2012 OLTP Database:

    1. Using Internet Explorer, download the AdventureWorks2012ForWindowsAzureSQLDatabase file from http://msftdbprodsamples.codeplex.com/releases/view/37304.

    2. Using Windows Explorer, unzip the file AdventureWorks2012ForWindowsAzureSQLDatabase.zip.

    3. Open a command prompt window as administrator and move to the folder holding the unzipped files, and then move to the AdventureWorks folder.

    4. Enter and run the following command. Replace {server} with the name of the database server from the previous step, and replace {login} and {password} with the login name and password that you specified when you created the database:

      CreateAdventureWorksForSQLAzure.cmd {server}.database.windows.net {login}@{server} {password}
      

      Note

      You should see the following error message:
      Error at or before line 10: Database 'AdventureWorks2102' already exists. Choose a different database name.
      You can ignore this error message.
      The command may take several minutes to complete successfully.

    5. Verify that the script completes without any further errors.

  4. Update the SalesOrderHeader and Person tables to include additional information required by the example solution:

    1. Return to Internet Explorer, and click Dashboard in the menu bar near the top of the page.

    2. In the Quick Glance pane, click Show connection strings.

    3. In the Connection Strings window, copy the ADO.NET connection string to the clipboard.

    4. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command. Replace {connection string} with the connection string in the clipboard. In this connection string, replace {your_password_here} with the password that you specified when you created the database:

      .\SetupDataGuidance.ps1 –createSqlTrackingId $true –createsqlPersonGuid $true –sqlConnectionString "{connection string}"
      

      Note

      The connection string must be enclosed within double quotes.

    5. Verify that the script completes without any errors.

  5. Start Visual Studio 2012 as an administrator and open the dag.sln solution.

  6. Update the DataAccess.MvcWebApi project in the ServicesImplementation folder to connect to the AdventureWorks2012 database hosted by using Windows Azure SQL Database:

    1. In the DataAccess.MvcWebApi project, open the Web.config file.
    2. In the <connectionStrings> section, find the AdventureWorksContext connection string.
    3. Replace the connectionString property with the ADO.NET connection string that you copied to the clipboard in step 3c. In the ADO.NET connection string, replace the text {your_password_here} with your database password.
    4. Save the Web.config file.
  7. Build and run the solution.

  8. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

Note

You can use the SetupDataGuidance.ps1 PowerShell script to configure each of the NoSQL repositories used by the sample application. You can use this script to configure Windows Azure Table service, as well as the MongoDB and Neo4j databases, and also copy product images to Windows Azure Blob service (In the default configuration, the web service stores product images in the Images folder, and passes a URL of an image to the UI web application when it needs to display the details for a product. You can move these images to Blob service if you prefer to serve them by using the Windows Azure Content Delivery Network (CDN)).
By default, all options are disabled, but you can selectively enable them by specifying the appropriate parameters when you run this script. The next section describes how to run this script and configure the solution to use Windows Azure Table service, MongoDB, Neo4j, and Blob service. The sections that follow illustrate how to configure each option separately if you wish to try different combinations of NoSQL databases.

To Run the Solution using Windows Azure Table Service to Store Shopping Cart Information

Note

This procedure only applies to the dag.azure solution. You cannot configure the dag.sln solution to use the Windows Azure Table service.

  1. Ensure that you have installed and configured the application and dependent software as described in the sections Set Up Your Development Computer and Build the Solution and Create the Adventure Works Database earlier in this document. Additionally, if the UI web application and the Adventure Works ASP.NET Web API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.
  2. Configure Windows Azure Table service:
    1. If you are using the local Windows Azure development fabric:

      1. Open a Windows Azure Command Prompt window as Administrator and run the following command:

        csrun /devstore
        
      2. Close the Windows Azure Command Prompt.

    2. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command. Replace {windows azure connection string} with the connection string that connects to the Azure storage account and key that you want to use to hold the shopping cart and blob images:

      Note

      If you are using the local Windows Azure development fabric, specify UseDevelopmentStorage=true for {windows azure connection string}. If you are using a storage account in the cloud, specify a connection string in the form DefaultEndpointsProtocol=https;AccountName={name};AccountKey={key} where {name} is the name of your Windows Azure storage account, and {key} is the storage key for this account.

      .\SetupDataGuidance.ps1 –createTableStorageShoppingCart $true –windowsAzureStorageConnectionString "{windows azure connection string}"
      
    3. Verify that the script completes without any errors.

    4. Close the Windows PowerShell window.

  3. Configure the DataAccess.MvcWebApi web service to store shopping cart information by using Windows Azure Table Service by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Shopping Cart Information in Windows Azure Table Service in this document.
  4. Build and run the solution.
  5. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

To Run the Solution using MongoDB to Store Product Information

Note

This procedure assumes that you have installed MongoDB and that you have started it running. For information on how to install and configure MongoDB, visit the MongoDB website at http://www.mongodb.org/.
For information on how to create a MongoDB virtual machine running under Windows Azure, see the release notes provided with this guide.

  1. Ensure that you have installed and configured the application and dependent software as described in the sections Set Up Your Development Computer and Build the Solution and Create the Adventure Works Database earlier in this document. Additionally, if the UI web application and the Adventure Works ASP.NET Web API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.
  2. Create the MongoDB product catalog database and populate it with product catalog information from the SQL Server database:
    1. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command. Replace {connection string} with the connection string for your SQL Server database, and replace {mongo connection string} with the address of the server hosting the MongoDB database:

      Note

      A MongoDB connection string has the formmongodb://{hostname} where {hostname} is the name of the computer hosting the MongoDB database.

      .\SetupDataGuidance.ps1 –sqlConnectionString "{connection string}" –createMongoProducts $true –mongoConnectionString "{mongo connection string}"
      
    2. Verify that the script completes without any errors.

  3. Configure the DataAccess.MvcWebApi web service to store product information by using MongoDB by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Product Information in MongoDB in this document.
  4. Build and run the solution.
  5. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

To Run the Solution using MongoDB to Order History Information

Note

This procedure assumes that you have installed MongoDB and that you have started it running. For information on how to install and configure MongoDB, visit the MongoDB website at http://www.mongodb.org/.
For information on how to create a MongoDB virtual machine running under Windows Azure, see the release notes provided with this guide.

  1. Ensure that you have installed and configured the application and dependent software as described in the sections Set Up Your Development Computer and Build the Solution and Create the Adventure Works Database earlier in this document. Additionally, if the UI web application and the Adventure Works Web ASP.NET API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.
  2. Create the MongoDB order history database:
    1. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command. Replace {connection string} with the connection string for your SQL Server database, and replace {mongo connection string} with the address of the server hosting the MongoDB database:

      Note

      A MongoDB connection string has the formmongodb://{hostname} where {hostname} is the name of the computer hosting the MongoDB database.

      .\SetupDataGuidance.ps1 – createMongoOrderHistory $true –mongoConnectionString "{mongo connection string}"
      
    2. Verify that the script completes without any errors.

  3. Configure the DataAccess.MvcWebApi web service to store order history information by using MongoDB by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Order History Information in MongoDB in this document.
  4. Build and run the solution.
  5. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

To Run the Solution using Neo4j to Store Product Recommendations

Note

This procedure assumes that you have installed and configured Neo4j. For information on how to install and configure Neo4j, visit the Neo4j website at http://www.neo4j.org/.
For information on how to create a Neo4j virtual machine running under Windows Azure, see the release notes provided with this guide.

  1. Ensure that you have installed and configured the application and dependent software as described in the sections Set Up Your Development Computer and Build the Solution and Create the Adventure Works Database earlier in this document. Additionally, if the UI web application and the Adventure Works Web ASP.NET API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.
  2. Populate the Neo4j database with the product information:
    1. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command. Replace {connection string} with the connection string for your SQL Server database, and replace {neo4j connection string} with the address of the server hosting the MongoDB database:

      Note

      A Neo4j connection string has the formhttp://{hostname}:7474 where {hostname} is the name of the computer hosting the Neo4j database.

      .\SetupDataGuidance.ps1 –sqlConnectionString "{connection string}" –createNeo4jRecommendations $true –neo4jConnectionString "{neo4j connection string}"
      
    2. Verify that the script completes without any errors.

  3. Configure the DataAccess.MvcWebApi web service to store product recommendations by using Neo4j by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Product Recommendation Information in Neo4j in this document.
  4. Build and run the solution.
  5. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

To Run the Solution using Windows Azure Blob Service to Store Product Images

Note

This procedure only applies to the dag.azure solution. You cannot configure the dag.sln solution to use the Windows Azure Blob service.

  1. Ensure that you have installed and configured the application and dependent software as described in the sections Set Up Your Development Computer and Build the Solution and Create the Adventure Works Database earlier in this document. Additionally, if the UI web application and the Adventure Works ASP.NET Web API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.
  2. Upload product image data to blob storage:
    1. If you are using the local Windows Azure development fabric:

      1. Open a Windows Azure Command Prompt window as Administrator and run the following command:

        csrun /devstore
        
      2. Close the Windows Azure Command Prompt.

    2. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command. Replace {windows azure connection string} with the connection string that connects to the Azure storage account and key that you want to use to hold the blob images:

      Note

      If you are using the local Windows Azure development fabric, specify UseDevelopmentStorage=true for {windows azure connection string}. If you are using a storage account in the cloud, specify a connection string in the form DefaultEndpointsProtocol=https;AccountName={name};AccountKey={key} where {name} is the name of your Windows Azure storage account, and {key} is the storage key for this account.

      .\SetupDataGuidance.ps1 –createBlobStorageImages $true –windowsAzureStorageConnectionString "{windows azure connection string}"
      
    3. Verify that the script completes without any errors.

  3. Configure the UI web application to retrieve product images from Windows Azure Blob service by performing the steps described in the section To Configure the User Interface to Download Product Images from Windows Azure Blob Service in this document.
  4. Build and run the solution.
  5. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

To Run the Solution using Windows Azure Table Service, MongoDB, and Neo4j NoSQL Databases, and Blob Service

Note

You cannot configure the dag.sln solution to use the Windows Azure Table service or the Windows Azure Blob service.
This procedure assumes that you have installed MongoDB and Neo4j, and that you have started them running. For information on how to install and configure MongoDB, visit the MongoDB website. For information on how to install and configure Neo4j, visit the Neo4j website.
For information on how to create a MongoDB virtual machine running under Windows Azure, see the release notes provided with this guide.

  1. Ensure that you have installed and configured the application and dependent software as described in the sections Set Up Your Development Computer and Build the Solution and Create the Adventure Works Database earlier in this document. Additionally, if the UI web application and the Adventure Works ASP.NET Web API web service are both running on the different computers, configure the UI web application by following the steps described in the section (Optional) Configure the UI Web Application.
  2. Configure Windows Azure Table service, create the MongoDB and Neo4j databases, and upload product image data to Blob service:
    1. If you are using the local Windows Azure development fabric:

      1. Open a Windows Azure Command Prompt window as Administrator and run the following command:

        csrun /devstore
        
      2. Close the Windows Azure Command Prompt.

    2. Open a Windows PowerShell window as Administrator, move to the folder holding the code for the solution, move to the DataAccess/src/scripts folder, and then run the following command. Replace {connection string} with the connection string for your SQL Server database, replace {mongo connection string} with the address of the server hosting the MongoDB database, replace {neo4j connection string} with the address of the server hosting the Neo4j database, and replace {windows azure connection string} with the connection string that connects to the Windows Azure storage account and key that you want to use to hold the shopping cart and blob images:

      Note

      A MongoDB connection string has the formmongodb://{hostname} where {hostname} is the name of the computer hosting the MongoDB database.
      A Neo4j connection string has the form http://{hostname}:7474 where {hostname} is the name of the computer hosting the Neo4j database.
      If you are using the local Windows Azure development fabric, specify UseDevelopmentStorage=true for {azure connection string}. If you are using a storage account in the cloud, specify a connection string in the form DefaultEndpointsProtocol=https;AccountName={name};AccountKey={key} where {name} is the name of your Windows Azure storage account, and {key} is the storage key for this account.

      .\SetupDataGuidance.ps1 –sqlConnectionString "{connection string}" –createMongoProducts $true –createMongoOrderHistory $true –mongoConnectionString "{mongo connection string}" –createNeo4jRecommendations $true –neo4jConnectionString "{neo4j connection string}" –createTableStorageShoppingCart $true –createBlobStorageImages $true –windowsAzureStorageConnectionString "{windows azure connection string}"
      
    3. Verify that the script completes without any errors.

    4. Close the Windows PowerShell window.

  3. Configure the DataAccess.MvcWebApi web service to store shopping cart information by using Windows Azure Table service by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Shopping Cart Information in the Windows Azure Table Service in this document.
  4. Configure the DataAccess.MvcWebApi web service to store product information by using MongoDB by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Product Information in MongoDB in this document.
  5. Configure the DataAccess.MvcWebApi web service to store order history information by using MongoDB by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Order History Information in MongoDB in this document.
  6. Configure the DataAccess.MvcWebApi web service to store product recommendations by using Neo4j by performing the steps described in the section To Configure the MvcWebApi Web Service to Store Product Recommendation Information in Neo4j in this document.
  7. Configure the UI web application to retrieve product images from Windows Azure Blob service by performing the steps described in the section To Configure the User Interface to Download Product Images from Windows Azure Blob Service in this document.
  8. Build and run the solution.
  9. Verify that the solution is running correctly by performing the steps described in the Check the Sample Functionality section in this document.

Configure the Application

This section describes how to modify the configuration to support each of the scenarios described in the guide.

To Configure the MvcWebApi Web Service to Store Shopping Cart Information in the Windows Azure Table Service

Note

This procedure only applies to the dag.azure solution. You cannot configure the dag.sln solution to use the Windows Azure Table service.

  1. In the DataAccess.MvcWebApi project, open the Web.config file.

  2. Find the following comment:

    <!-- mappings for in-memory repositories for all NoSQL persistence stores -->
    
  3. In the section below this line, comment out the following line that registers the in-memory shopping cart repository:

    <register type="IShoppingCartRepository" mapTo="DataAccess.Repo.Impl.InMemory.ShoppingCartRepository, DataAccess.Repo.Impl.InMemory" />
    
  4. Find the following comment:

    <!-- mappings for table storage repositories -->
    
  5. Uncomment the following lines that register the repository object that uses Windows Azure Table service:

    <register type="IShoppingCartRepository" mapTo="DataAccess.Repo.Impl.TableService.ShoppingCartRepository, DataAccess.Repo.Impl.TableService">
        <lifetime type="HierarchicalLifetimeManager" />
    </register>
    
  6. Save the web.config file.

  7. If you are using a Windows Azure storage account in the cloud and not the local development fabric:

    1. In the Cloud project, expand the Roles folder, and then double-click the DataAccess.MvcWebApi file.
    2. In the editor window, click Settings.
    3. Modify the TableStorageConnectionString setting and specify the connection string for your Windows Azure storage account.
    4. Save the DataAccess.MvcWebApi file.

To Configure the MvcWebApi Web Service to Store Product Information in MongoDB

  1. In the DataAccess.MvcWebApi project, open the Web.config file.

  2. Find the following comment:

    <!-- mappings for in-memory repositories for all NoSQL persistence stores -->
    
  3. Comment out the lines that register the in-memory category and product repositories:

    <register type="ICategoryRepository" mapTo="DataAccess.Repo.Impl.InMemory.CategoryRepository, DataAccess.Repo.Impl.InMemory" />
    <register type="IProductRepository" mapTo="DataAccess.Repo.Impl.InMemory.ProductRepository, DataAccess.Repo.Impl.InMemory" />
    
  4. Find the following comment:

    <!-- mappings for mongo repositories -->
    
  5. Uncomment the lines that register the category and product catalog repository objects that use MongoDB:

    <register type="ICategoryRepository" mapTo="DataAccess.Repo.Impl.Mongo.CategoryRepository, DataAccess.Repo.Impl.Mongo">
        <lifetime type="HierarchicalLifetimeManager" />
        <constructor>
            <param name="hostName" type="System.String">
                <value value="127.0.0.1" />
            </param>
            <param name="databaseName" type="System.String">
                <value value="AdventureWorks" />
            </param>
        </constructor>
    </register>
    
    <register type="IProductRepository" mapTo="DataAccess.Repo.Impl.Mongo.ProductRepository, DataAccess.Repo.Impl.Mongo">
        <lifetime type="HierarchicalLifetimeManager" />
        <constructor>
            <param name="hostName" type="System.String">
                <value value="127.0.0.1" />
            </param>
            <param name="databaseName" type="System.String">
                <value value="AdventureWorks" />
            </param>
        </constructor>
    </register>
    
  6. If you are running MongoDB on a remote computer, change the value of the hostName parameter both repository objects to the address of the remote computer.

  7. Save the web.config file.

To Configure the MvcWebApi Web Service to Store Order History Information in MongoDB

  1. In the DataAccess.MvcWebApi project, open the Web.config file.

  2. Find the following comment:

    <!-- mappings for in-memory repositories for all NoSQL persistence stores -->
    
  3. Comment out the line that registers the in-memory order history repository:

    <register type="IOrderHistoryRepository" mapTo="DataAccess.Repo.Impl.InMemory.OrderHistoryRepository, DataAccess.Repo.Impl.InMemory" />
    
  4. Find the following comment:

    <!-- mappings for mongo repositories -->
    
  5. Uncomment the lines that register the order history repository object that uses MongoDB:

    <register type="IOrderHistoryRepository" mapTo="DataAccess.Repo.Impl.Mongo.OrderHistoryRepository, DataAccess.Repo.Impl.Mongo">
        <lifetime type="HierarchicalLifetimeManager" />
        <constructor>
            <param name="hostName" type="System.String">
                <value value="127.0.0.1" />
            </param>
            <param name="databaseName" type="System.String">
                <value value="AdventureWorks" />
            </param>
            <param name="setWriteConcernToJournal" type="System.Boolean">
              <value value="True" />
            </param>
        </constructor>
    </register>
    
  6. If you are running MongoDB on a remote computer, change the value of the hostName parameter for the repository object to the address of the remote computer.

  7. Save the web.config file.

To Configure the MvcWebApi Web Service to Store Product Recommendation Information in Neo4j

  1. In the DataAccess.MvcWebApi project, open the Web.config file.

  2. Find the following comment:

    <!-- mappings for in-memory repositories for all NoSQL persistence stores -->
    
  3. Comment out the line that registers the in-memory product recommendations repository:

    <register type="IProductRecommendationRepository" mapTo="DataAccess.Repo.Impl.InMemory.ProductRecommendationRepository, DataAccess.Repo.Impl.InMemory" />
    
  4. Find the following comment:

    <!-- mappings for Neo4j repositories -->
    
  5. Uncomment the lines that register the context object and repository for using Neo4j:

    <register type=" IProductRecommendationRepository" mapTo="DataAccess.Repo.Impl.Neo4j.ProductRecommendationRepository, DataAccess.Repo.Impl.Neo4j">
        <lifetime type="HierarchicalLifetimeManager" />
        <constructor>
            <param name="databaseUrl" type="System.String">
                <value value="https://localhost:7474/db/data" />
            </param>
        </constructor>
    </register>
    <register type="IProductRecommendationRepository" mapTo="DataAccess.Repo.Impl.Neo4j.ProductRecommendationRepository, DataAccess.Repo.Impl.Neo4j"  />
    
  6. If you are running Neo4j on a remote computer, modify the value of the databaseUrl parameter and replace localhost with the address of the server hosting your Neo4j database.

  7. Save the web.config file.

To Configure the User Interface to Download Product Images from Windows Azure Blob Service

Note

This procedure only applies to the dag.azure solution.

  1. In Visual Studio, in the dag.azure solution, in the UI folder, in the UI.Mvc project, open the web.config file.

  2. Uncomment the following line**:**

    <add key="imgCdnUrl" value="http://127.0.0.1:10000/devstoreaccount1"/>
    
  3. If you are storing images data in the cloud by using Windows Azure CDN rather than the local development fabric, change the value property to http://your-account-name.blob.core.windows.net where your-account-name is the name of your Windows Azure storage account.

  4. Comment out the following line:

    <add key="imgCdnUrl" value="http://127.0.0.1:12345/images"/>
    
  5. Save the web.config file.

Check the Sample Functionality

This section describes how to verify that the application is running correctly.

  1. If you are running the solution on your development computer, Internet Explorer will be open and should be displaying the user interface for the Adventure Works Shopping web application (the UI.Mvc application).
  2. If you have deployed the solution to the cloud, open Internet Explorer and move to the URL http://service.cloudapp.net/, where service is the name of the cloud service that you created to host the UI.Mvc web application and DataAccess.MvcWebApi web service.
  3. Verify that the application displays a list of product categories (Accessories, Bikes, Clothing, and Components) and their images.
  4. Click the Bikes category and verify that the application displays three subcategories (Mountain Bikes, Road Bikes, and Touring Bikes).
  5. Click the Touring Bikes subcategory and verify that a list of touring bikes is displayed.
  6. Click the first touring bike (Touring-20000 Blue, 60) and verify that the details for this bike are displayed.
  7. If this is the first time that you have run the application, perform the following tasks:
    1. Click Register in the menu bar at the top of the page.
    2. On the Register page, provide the details for a new account and then click Register.
    3. Verify that the message Hello, username appears in the menu bar at the top of the page where username is the email address of the user that you just registered.
  8. If you have run the application previously, perform the following tasks:
    1. Click Log in in the menu bar at the top of the page.
    2. On the Log in page, enter your username and password, and then click Log in.
    3. Verify that the message Hello, username appears in the menu bar at the top of the page.
  9. Click Add to Cart and verify that the message The item has been added to the shopping cart is displayed.
  10. Click the Shopping Basket icon in the menu bar at the top of the screen, and verify that the shopping basket contains the Touring-2000 Blue, 60 touring bike.
  11. Click Checkout.
  12. On the Checkout page, verify that your shipping address, billing address, and credit card details appear, and then click Confirm.
  13. On the Thanks! Your order has been submitted! page, click Continue shopping.
  14. Click My Orders in the menu bar at the top of the page, and verify that the new order appears in the Your Orders history page (there should be two entries, marked Pending and Completed).
  15. Click the Tracking Id for either entry for the new order and verify that the details of the order are displayed.
  16. Click Log off in the menu bar at the top of the page.
  17. Close Internet Explorer.

Next Topic | Previous Topic | Home | Community