Skip to content

Configuring WPF → Web API → SQL Server

Aaron Hanusa edited this page Jan 24, 2016 · 6 revisions

WPF → Web API → SQL Server

WPF → API &#8594 In Memory

Watch the configuration video here.

In this scenario, the WPF client consumes business services that are injected with data proxies that use HTTP (via HttpClient) to communicate with the Web API application. In turn, the Web API application uses business services that are injected with data proxies that use Entity Framework 6.0 to communicate with a SQL Server database.

To configure the WPF application to use business services that are injected with HTTP data proxies, locate the MainWindow_Loaded event handler in the MainWindow class and ensure the following line exists:

void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    ConfigureHttpClientUsage();
}

An important thing to note is that the configuration code in ConfigureHttpClientUsage() uses two business services that can be referred to as client service proxy classes. Let's take a look at the code:

wpf http config

The classes highlighted in red represent client service proxy classes. These classes inherit from other service classes and override command methods to bypass any command logic to simply marshal calls to the data proxy. To learn more about the necessity of client service proxies, see using client service proxies.

The next step is to configure the Web API project. The Web API project uses dynamic dependency injection to create business services and data proxies that will be injected into the API controllers. To configure the Web API project to consume Entity Framework data proxies, open the DependencyInjection.config file.

Notice that there are two configuration sections for data proxies; one for Entity Framework and one for In-Memory, respectively. Simply ensure that the Entity Framework Data Proxies section is uncommented and the In Memory Data Proxies section is commented out.

Before running the application, be sure to setup SQL Server after changing the configuration.

To run the application, set the WPF and Web Api projects as the startup projects in the solution and run the application.

Clone this wiki locally