Integrate MVC Web Applications with Business Central SOAP

Integrate MVC Web Applications with Business Central SOAP

About MVC (Model View Controller)

The Model-View-Controller (MVC) architectural pattern divides the apps into three main components: Model, View and Controller. The MVC pattern lets you create simpler apps to update and test against traditional monolithic apps.

Models: classes that represent the data of the app. Model classes use the validation logic to apply business rules for such data. Typically, model objects retrieve and store the model state in a database.

Views: components that display the user interface of the app; typically this user interface presents the model data.

Controller: classes that handle browser requests. They retrieve model data and call view models that return a response. In an MVC application, the view presents only the information; the controller manages and responds to user input and interaction actions.




About Razor Pages

Razor Pages is a new feature of ASP.NET Core MVC that simplifies and makes the writing of code focused on pages more productive.

Razor is a markup syntax for embedding server-based code in Web pages. The Razor syntax consists of Razor, C # and HTML markup. Files containing Razor typically have the cshtml extension. Razor supports C# and uses the @ symbol for the transition from HTML to C#. Razor evaluates C # expressions and renders them in the HTML output.

Pagina Home o di indice



Comparing SOAP and OData Web Services

Differences between SOAP and Odata web services for Dynamics 365 Business Central-

SOAP Web Services

SOAP web services allow full flexibility for building operation-centric services. The most common type of messaging pattern in SOAP is the Remote Procedure Call (RPC), where one network node (the client) sends a request message to another node (the server), and the server sends a response message to the client.

OData Web Services

The OData standard is well suited for web service applications that require a uniform, flexible, general-purpose interface for exposing create retrieve update delete (CRUD) operations on a tabular data model to clients. OData supports Representational State Transfer (REST)-based data services.

Example of SOAP


Example of OData



#1 – NEW STYLE APPS: Introduction to ASP.NET Core MVC and Razor Pages

Create a New Project Web ASP.NET Core

Create a new MVC App

MVC Solution (MVC Projects Sections – Models, Controllers, Views)

MVC Web Application will be deployed on IIS Express – example



Scenario1: Read Companies names form Business Central Web Services List and show results on Web Page.

Scenario2: Read Item List and Insert a New Item using WS (Codeunit and Card Page).

“Services List” is exposed as Web Service (SOAP API), the same is for “ItemCard” & “ItemList

Services Page<TenantID>/WS/Services

Item Pages<TenantID>/WS/COMPANYNAME/Page/ItemList<TenantID>/WS/COMPANYNAME/Page/ItemCard

Microsoft Demo Source


Create a New Project “DemoBCWebApp”

Add a Web Reference to Services.

Configure the WFC Web Reference (in this example the System Services WS show Companies, the same for other Web Services), assign a namespace ex: BCSOAP

MVC Application Structure: “MODELS, CONTROLLERS, VIEWS”


The Core of the Web Application


On HomeController.cs you can recall the “CreateItem” function exposed by Web Service


You can define an “ItemList” function to retrieve data from the ItemList exposed Web Service.

You need to use these include:

  • System.Web, System.Web.Mvc and others, all the exposed Web Service one by one
  • You have to define User, Password for connection to Web Services

Define the URL Connection, User and Password

URL Connection Sample and Service Login example

systemService.Url = “<TenantID>/WS/SystemService?tenant=<tenant>=FIN”

NetworkCredential nc = new NetworkCredential(“user”, “password”)


About Security

** User\Password: is possibile to Crypt\Decrypt password or masquerade the code with Dotfuscator (many post available about these issues)

** User Login Page: you can activate a separate login page – Login Wrapper (you can use Google Sites as Master Browser, read my post about Power BI reports publications)

Simple User Login Form example in ASP.Net


using System.Web.Security;

User Login Page: example


Integrated in .NET Application

Casella di ricerca


MVC Application Main Objects

  • Global.asax, _Layout.cshtml and AppConfig


Web Config





View and Display Data, in this case Companies names will be displayed in the Web Page.

Index.cshtml the core code to display data

@foreach (var com in Model)


…. Loop and write @com


Call mapped Web Services: Call the WSCdu codeunit to insert data.



Is a Web Application, style Is a lot different from classic desktop apps.

Login Page

Home Page

“Insert” and Show “added data” after insert

  • From ButtonInsert” you can call the “CreateItem” Function from exposed Codeunit to insert a new item or write directly to another Web Services exposed (ex: ItemCard)

Codeunit WSCdu > “CreateItem” Function

List of Exposed Web Services<TenantID>/WS/COMPANYNAME/Page/ItemList<TenantID>/WS/COMPANYNAME/Page/ItemCard<TenantID>/WS/ COMPANYNAME /Codeunit/WSCdu_Functions

Codeunit WSCdu > CreateItem Function

Web Services references

Insert New Item from Codeunit Web Service o from ItemCard Web Service (two different methods)

“Inserted Item” message: “Success” or “Failure”

Success message

Failure message


#3 – OLD STYLE APP – CLASSIC C# Console Application

You can achieve the same result using a classic desktop application.

ADD a Web Reference – “SystemService” SOAP Web Service


systemService.Url = “<TenantID>/WS/SystemService?tenant=<tenant>=FIN”

NetworkCredential nc = new NetworkCredential(“user”, “password”)

RUNNING TEST > List of ALL companies will be displayed in Console Mode

4 thoughts on “Integrate MVC Web Applications with Business Central SOAP

  • 30 October 2019 at 10:36 AM

    Hello Roberto,
    I’ve found this blog searching about info to create a web Api for a oData webService. The process will the the same in this case as SOAP?

    Thank you very much

  • 7 January 2020 at 6:38 AM

    how can we delete and edit records from Item list through web to business central?

  • 10 June 2020 at 4:00 PM

    Detailed one roberto. Will include this article in our mvc tutorial.

  • 10 June 2020 at 4:00 PM

    Detailed one roberto. Will include this article in our mvc tutorial.

Comments are closed.