How to Create SOAP Web Service Using WSDL in ASP.NET Core

In this tutorial, we will guide you through the process of implementing a SOAP (Simple Object Access Protocol) service using WSDL (Web Services Description Language) in Visual Studio .Net Core. SOAP is a widely used protocol for exchanging structured information in web services, and WSDL serves as a standard for describing the web service interface.Despite the rise of REST, over 70% of enterprise-level banking systems still rely on SOAP for secure, reliable web services, showcasing its critical role in sectors like finance and healthcare, with giants like Salesforce extensively using SOAP APIs.

“NetSuite, a leading cloud ERP from Oracle, still offers SOAP APIs which are capable of performing batch transactions via API, whereas such a feature is not available with its REST API.”

“ClearBooks, a top accounting software provider, exclusively offers a SOAP API, emphasizing the protocol’s importance in secure and complex financial data transactions.”

Let’s deep dive into how to consume or implement any SOAP-based API in ASP.net Core

How to Create SOAP Web Service Using WSDL in Visual Studio .NET Core

Creating a SOAP web service WSDL in Visual Studio ASP.NET Core

Launch the Visual Studio 2022 on your machine.

Launch the Visual Studio 2022 on your machine.

To use the code examples provided in this article, you should have Visual Studio 2022 installed in your system. If you don’t already have a copy, you can download Visual Studio 2022 here

    Create a New Project.

    Create a New Project

    Navigate to “File” > “New” > “Project…”
    Choose the appropriate project template, such as “ASP.NET Core WebAPI”

    Set Up the Project in ASP.NET Core Web API and configure project settings, including the project name and location.

    Set Up the Project in ASP.NET Core Web API and configure project settings, including the project name and location

    Install the SoapCore package

    In the NuGet Package Manager window, locate the SoapCore package and proceed to install it.

    You also have the option to install the SoapCore package using the NuGet Package Manager console. Simply input the following command line to initiate the installation process.

    Install the SoapCore package

    Define the Data Contract.

    Define the Data Contract

    In the data contract, we define the characteristics of each Soapservice data type, such as their types, names, and any rules or restrictions. This ensures that clients and services, built with different programming languages or platforms, can communicate effectively.

    Define the Service Contract

    Define the Service Contract

    A service contract has two parts: the service interface describing the service and additional details like message formats and security, all defined using the ServiceContract attribute in C#. This attribute marks an interface or class as a service contract.

    Create a service and add a method of service with customer data

    Create a service and add method in service with customer data

    Register a SOAP service in the Program.cs

    Register a SOAP service in Program.cs

    Configure the HTTP request pipeline for the SOAP endpoint in Program.cs

    Configure the HTTP request pipeline for the SOAP endpoint in Program.cs

    Complete the source code of the Program.cs

    Complete source code of the Program.cs

    Run the SOAP service

    Launch the application and visit the specified endpoint to view the generated WSDL.
    Run the SOAP service
    Run the SOAP service

Consume WSDL in .NET Core

Create .NET Core WEB API project same as shown above step

Create client applications to consume the SOAP service. Visual Studio can assist in generating client code based on the WSDL.

Generate reference code from a WSDL file, Right click on “Manage Connected Services”

Generate reference code from a WSDL file, Right click on “Manage Connected Services

Click on “Add a service reference”

Click on “Add a service reference”

Select “WCF Web Service “

Select “WCF Web Service

Insert the WSDL URI

Insert the WSDL URI

click “Go,” and you’ll receive a list of services, methods, and a Namespace. Use this Namespace to reference methods in the project.

Clicking “Next” allows configuration,

Clicking

such as specifying the type of collections to generate. In this example, we’ll choose System.Collections.Generic.List.

In the final configuration screen,

In the final configuration screen

choose between public/private classes and opt for synchronous or default asynchronous method generation.

Click “Finish” to initiate scaffolding, and your classes will be generated.

Click

    Once the process is complete,

    Once the process is complete

    find the connected service in the Solution Explorer, containing the generated reference with configured endpoints and methods. Choosing synchronous method generation results in various available methods.

    Create a new controller

    <a href=Create a new controller" />

    To illustrate how to utilize the recently established connected service using SOAP Client. To communicate with the connected service, create a client by referencing the Customer Reference. Indicate the endpoint to be used in the client.

    Execute the project and perform testing in Swagger.Execute the project and perform testing in Swagger

    Conclusion

    Implementing a SOAP service using WSDL in Visual Studio is a straightforward process, and it provides a robust foundation for building interoperable and standardized web services. By following these steps, you can create a SOAP service, define its contract, and seamlessly integrate it into your applications.

    Remember to adapt the instructions based on your specific project requirements and the version of Visual Studio you are using.

    Keep with us for more tips and tricks about the ASP.NET Core Development concept.

    I hope you would like my blog to help provide a robust foundation for building interoperable and standardized web services. You can share this blog via a social button to help other Asp.Net Developers. As We are at Satva Solutions, we provide API integration services in any ASP.NET MVC/Core application.

    Next, read this:

    Get started with ASP.NET Core DevelopmentContact Us Article by

    Jignasha Rathod

    Jignasha Rathod is a Technical Analyst with over a decade of experience in the IT industry. She excels in .NET, CI/CD, GitHub, Azure. and has a proven track record in project management, leadership, API integrations, and Azure AI and ML.net . Jignasha is focused on performance enhancement and possesses deep domain expertise in open source CMS ( umbraco, orchard cms ) accounting, CRM, ERP (SAP, NetSuite, Business Central) and e-commerce. Her extensive experience spans across both B2B and B2C e-commerce platforms, and she is leveraging AI and ML technologies to drive innovation and efficiency in client projects.