Learn how to use the Microsoft Connected Services extension to consume a WCF SOAP service from ASP.Net Core Credit: Gremlin / Getty Images Until REST APIs came along, SOAP (Simple Object Access Protocol) was the de facto standard protocol on which web services were based. When working in ASP.Net Core, you might well encounter the need to consume data from third-party or external services that use SOAP as the protocol and XML as the message exchange format. In this article we will explore how we can consume a WCF (Windows Communication Foundation) SOAP service in ASP.Net Core. Create a WCF SOAP service in Visual Studio 2017 WCF is a secure, reliable, and scalable messaging platform that provides a unified programming model for developing service-oriented applications in .Net. You can take advantage of WCF to build a SOAP service, using XML as the message exchange format, or a REST service, using JSON as the message exchange format. In this section we will create a WCF SOAP service. This service will be consumed by an ASP.Net Core application that we will create in the next section. Follow the steps below to create a WCF SOAP service in Visual Studio 2017. Launch the Visual Studio 2017 IDE. Click File > New > Project. Select WCF from the list of project templates displayed in the left pane. Select “WCF Service Application” from the right pane. Specify a name for your WCF service project. Click OK. IDG Figure 1: Creating a WCF SOAP Service in Visual Studio 2017. A WCF service is comprised of the following parts: Service class Service contract One or more operation contracts One or more endpoints Hosting environment When working with WCF, you first need to create a service contract and then define the service operations or operation contracts in it. A service contract is used to specify the operations that are available for the service client to consume. (You can learn more about WCF services from this article.) Here is a service contract that contains one service method. [ServiceContract] public interface IAuthorService { [OperationContract] List<string> GetAuthorNames(); } Note the use of the OperationContract attribute on the GetAuthorNames method. The service class, AuthorService, implements the IAuthorService interface. Here is the code that comprises the AuthorService class. public class AuthorService : IAuthorService { public List<string> GetAuthorNames() { List<string> lstAuthors = new List<string>(); lstAuthors.Add("Joydip Kanjilal"); lstAuthors.Add("Steve Smith"); lstAuthors.Add("Michael Stevens"); return lstAuthors; } } And that’s all you need to do to build a simple SOAP service in WCF. You can now open a web browser and test the service. Create an ASP.Net Core Web API project in Visual Studio 2017 In this section we will create our ASP.Net Core Web API application. This will be a REST-based web API. Follow the steps outlined below to create a new ASP.Net Core project in Visual Studio 2017. In Visual Studio 2017, click File > New > Project. Select the “ASP.Net Core Web Application” project template. Specify the name and location for your project. Click OK. In the “New ASP.Net Core Web Application” dialog window, select .Net Core. Select ASP.Net Core 2.1 as the project’s version. Select “Web API” as the project template. Uncheck the “Enable Docker Support” and “Configure for HTTPS” check boxes as we will not need them here. Ensure that the message “No Authentication” is displayed; we won’t be needing authentication here either. Click OK. IDG Figure 2: Creating an ASP.Net Core Web API application in Visual Studio 2017. This will create a new ASP.NET Core Web API application. So far so good. In the next section we will examine how we can consume the SOAP service. Consume a SOAP service in ASP.Net Core Unlike legacy ASP.Net, ASP.Net Core doesn’t have the Add Service Reference option that allows us to add external service references as connected services. To consume the SOAP service we created earlier, we can take advantage of the Microsoft WCF Web Service Reference Provider. Follow the steps below to add a connected service and use this provider to reference the SOAP service. In the Solution Explorer window, select the ASP.Net Core Web API project. Right-click and select Add > Connected Service. Click on the “Microsoft WCF Web Service Reference Provider” and wait for the “Configure WCF Web Service Reference” wizard to open. In the “Configure WCF Web Service Reference” window, specify the URI of the SOAP service in the as shown in Figure 3 below. Click Next. In the next window, you can specify the data type options. We’ll skip that step here. Click Next. In the next window, you can specify the access level. Let it be public (the default). Click Finish. IDG Figure 3: Configuring the Connected Service in ASP.Net Core. In a series of automated steps, Visual Studio will download the metadata from the SOAP service we specified earlier, generate the service reference code, and store the code in a file named Reference.cs inside the Connected Services node. The necessary packages will also be installed, and the project file updated accordingly. IDG Figure 4: The WCF SOAP service reference has been added to the ASP.Net Core Web API project. And that’s it! You can now instantiate the service client and consume the SOAP service in your controller method using the following code. [HttpGet] public async Task<string[]> Get() { ServiceReference1.AuthorServiceClient authorServiceClient = new ServiceReference1.AuthorServiceClient(); var data = await authorServiceClient.GetAuthorNamesAsync(); return data; } WCF Connected Service is an extension in Visual Studio that allows you to generate SOAP service references in your ASP.Net Core application for services that are built using WCF. You can also leverage connected services in ASP.Net Core to connect to Azure Storage services. We will explore this option in a later post here. Related content news Wasmer WebAssembly platform now backs iOS Wasmer 5.0 release also features improved performance, a leaner codebase, and discontinued support for the Emscripten toolchain. By Paul Krill Oct 30, 2024 2 mins Mobile Development Web Development Software Development news analysis What Entrust certificate distrust means for developers Secure communications between web browsers and web servers depend on digital certificates backed by certificate authorities. What if the web browsers stop trusting your CA? By Travis Van Oct 30, 2024 9 mins Browser Security Web Development Application Security news Next.js 15 arrives with faster bundler High-performance Rust-based Turbopack bundler moves from beta to stable with the latest update of the React-based web framework. By Paul Krill Oct 24, 2024 2 mins JavaScript React Web Development feature WasmGC and the future of front-end Java development WebAssembly’s garbage collection extension makes it easier to run languages like Java on the front end. Could it be the start of a new era in web development? By Matthew Tyson Oct 16, 2024 10 mins Web Development Software Development Resources Videos