Windows Communication Foundation (WCF) remains a mature technology, so there is little difference in developing these applications and services with VS2015. Since WCF is a technology focused on network communications, the visible changes in Visual Studio are quite small. However, with .NET Framework 4.6.2, there have been many bug fixes and stability enhancements to ensure that it performs as expected.
WCF is Microsoft's framework designed for use in creating applications based on service-oriented architecture. Some of the features provided by WCF include interoperability, service metadata, data contracts, and security. For in-depth information on using WCF, refer to Microsoft's introduction at https://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx, and the general reference guide at http://msdn.microsoft.com/en-us/library/dd456779(v=vs.110).aspx.
In this recipe, you'll create a task-based WCF service so that you can see what has changed. A sample WPF application will call this sample WCF service.
Simply start a premium version of VS2015 (or Visual Studio Community), and you will be ready to go.
As you create these WCF applications, you will see how Visual Studio simplifies the process. Let's get started:
app.config
file for the WPF application, locate the <endpoint>
configuration section, and hover the mouse over the name
attribute. A tooltip will appear to explain what this attribute is for, as shown in the following screenshot. Given the issues people have historically had with understanding the details in WCF configuration, this IntelliSense information is very welcome.<client />
section by typing <endpoint binding=
. IntelliSense will kick in to show you the values that can be placed inside the quotes. That makes editing WCF configurations much simpler than trying to remember what all the valid values are. Select the basicHttpBinding
value, as shown in the following screenshot:The recipe asks you to add it here so you can see the new IntelliSense support for WCF configurations. A complete WCF tutorial is outside the scope of this book, but once you finish the recipe, try manually adding support for https using the basicHttpsBinding
class. For now, we will comment out the second endpoint that we just added.
MainWindow.xaml
file, and change the <Grid>
element to a <StackPanel>
element. Add a button and a textbox to the <StackPanel>
element, as listed in the following code:<StackPanel> <Button x:Name="btnAsync" Click="btnAsync_Click_1"> click!</Button> <TextBlock x:Name="txtText">Not yet populated </TextBlock> </StackPanel>
MainWindow.xaml.cs
, and add code for the button click event handler so that it calls out to the WCF service, as follows:async private void btnAsync_Click_1(object sender, RoutedEventArgs e){ using (var client = new ServiceReference1.Service1Client()) { var result = await client.GetDataAsync(3); txtText.Text = result; } }
async
call to the WCF service. The text below the button should update to say You entered: 3, proving that the call to the service worked.As mentioned earlier, the Add Service Reference dialog box can generate task-based proxy classes that you can call from your code with an await
keyword. This makes asynchronous calls to services much easier to write, though you can still call the blocking, synchronous methods if you need to. The generated code contains both the synchronous method call as well as the task-based call.
WCF's ServiceModel Metadata Utility Tool (svcutil.exe
) can also be used to generate task-based proxies if you prefer to use the command-line tool instead of Visual Studio.
18.191.223.123