Steps to Create Web Service in .NET and Consume in D365 F&O Project
Creating a .NET Web Application can be an easy process if it is done right. Our DEV IT engineers are here to guide you through the process of creating a web service in .NET and then Consuming it in D365 F&O.
Firstly, you will need to import the exchange rate in AX using http://currencyconverter.kowabunga.NET/converter.asmx
Create Webservice in .NET
You must first create a webservice in your .NET project before consuming the external web service. Here are the steps you need to perform:
- Go to Visual Studio 2015 and create a New Project
- Select an ASP.NET Web Application
- Go to Solution Explorer, right-click on your project, and select add service reference.
Add web service URL http://currencyconverter.kowabunga.NET/converter.asmx and click on the “Advanced” button as shown in the screen below.
A new window will open as shown in the screen below:
Click on the “Add Web Reference” button and add the web service’s URL and update the web reference name as shown in the screen below. Click on “Add Reference” when done.
The web reference will be added in your project as shown below:
– Add a new item with the name “GetExchangeRate.asmx”
– Add a method to access the external web service method with the code shown below. This will allow you to access the methods of the Kowabunga web service:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using dev_KowabungaWS.KowabungaWR;
namespace dev_KowabungaWS
{
/// <summary>
/// Summary description for GetExchangeRate
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class GetExchangeRate : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string GetLastUpdateDate()
{
KowabungaWR.Converter cr = new KowabungaWR.Converter();
return cr.GetLastUpdateDate().ToString();
}
}
}
– Build and run the project and then add GetExchangeRate.asmx in the URL as shown below:
Click on the method GetLastUpdateDate to call the web service method.
Consume the Webservice in Your Dynamics Project
– Create the Model and Project for Dynamics.
Right-click on the solution explorer project and add the reference. Next, browse to the .dll file and add the .dll file of the .NET web service project in the Dynamics Project.
To verify the service, add a new Item with name Runbase Class (Job) and enter the code as shown below:
dev_KowabungaWS.GetExchangeRate KW = new dev_KowabungaWS.GetExchangeRate();
info(strFmt("%1", KW.GetLastUpdateDate()));
Wrapping Up
We hope that this review would have helped you understand the ins and outs of creating a .NET web service and consuming it in your D365 FO Suite. If you have any queries regarding the same, feel free to post a comment and our DEV IT experts will be happy to help you out.