Showing posts with label WebAPI. Show all posts
Showing posts with label WebAPI. Show all posts

Custom Web Service in few steps D365FO

Custom Web Service in few steps D365FO


In this article, I will explain how we can create a basic custom Web Service in D365FO with few steps.



Step-1 Create a class with the name of IntegrationService and write a method get foo.

Reference screenshot

public class IntegrationService  
{
    public str getFoo()
    {
        return "Hello World";
    }
}

Step-2  Create Add new Service and associate your class with newly created service
Reference screenshot



Step-3 Class association with service.
Reference screenshot



Step-4 Add the method of your class in the service operations node that you want to expose.
 Reference screenshot



Step-5 Add a Service group and associate your service with the service group.

Step-6 Set the service property Auto deploy= YES

Reference screenshot





Step-7 Perform Build & Sync and verify from browser.
Reference screenshot


Service URL 
https://usnconeboxax1aos.cloud.onebox.dynamics.com/api/services/[ServiceGroupName]/[ServiceName]/[MethodName]

Sample
https://usnconeboxax1aos.cloud.onebox.dynamics.com/api/services/IntegrationGroup/IntegrationService/getfoo


Follow this link to consume web service using POSTMAN

Support Faryal's Cusine


Dynamics 365 Finance & Operation WebAPI with POST MAN


Dynamics 365 Finance & Operation WebAPI with POSTMAN


Most of the time we used 3rd Party tools like fiddler, Post Man and SoupUI as clients to consume web services.

In this blog i will explain, How can we use POSTMAN to consume Web-API by using Oauth2 Azure Authentication.


Step-1 Download the POSTMAN from this link.

Step-2 Register The Azure Application (Web API). You can follow this link

Step-3 Add the below URL in the Reply URL section https://www.getpostman.com/oauth2/callback. check the below screenshot.



Step-4 Once App registration completed Enter Application ID in D365FO

Reference screenshot



Step-5 Open POST man and navigate to Authorization Tab and select OAuth2 as Authentication Type.

Reference screenshot



Step-6 Click on Get New Access Token. A Popup will appear.

Reference screenshot



Step-7 Fill the required fields Like below

Call Back URL > You can't change this.
Token Name (As per your requirement)
Auth URL

https://login.windows.net/YourTenant.com/oauth2/authorize?resource=https://EnvironmentURL.operations.dynamics.com

Access Token URL
https://login.windows.net/YourTenant.com/oauth2/token?resource=https://EnvironmentURL.operations.dynamics.com

You can find the tenant from AX as well. Open D365FO Click on the Setting icon. you can find it the on the top right of the screen then click on about.





Client ID > Application ID You Registered On Azure Portal
Secret Key > Enter the secret key you generate against your Azure Application.



If you don't provide a secret key then a popup window will appear for login.


Reference Screenshot


Step-8 Click on Request Toke. Within 4 to 5 seconds you will get the Azure Authentication Token.

Step-9  Now select the Header value from the drop-down and click on USE token to add this token in your request.

Reference screenshot



Step-10 Navigate to Header Tabs for the verification of the Authorization token in your request

Reference screenshot


Step-11 Enter the Complete service URL and click on send. in my case, I have called getFoo service.

Reference screenshot



Please check the above screenshot. You will find the successful result 


Please feel free to contact me if you are facing any issues during the implementation of this blog.



Support Faryal's Cusine


Azure App Registration


Azure App Registration



Any application that wants to use the capabilities of Azure AD must first be registered in an Azure AD tenant. This registration process involves giving Azure AD details about your application, such as the URL where it’s located, the URL to send replies after a user is authenticated, the URI that identifies the app, and so on.

To register a new application using the Azure portal
1.       Sign in to the Azure portal.
2.       If your account gives you access to more than one, click your account in the top right corner, and set your portal session to the desired Azure AD tenant.
In the left-hand navigation pane, click the Azure Active Directory service, Click App registrations
and click New application registration.





Following are the apps I have already registered as per my requirement.


In the Azure portal, we have two types of Apps

·         Web API

Select "Web app / API" for client applications and resource/API applications that are installed on a secure server. This setting is used for OAuth confidential web clients and public user-agent-based clients. The same application can also expose both a client and resource/API.

·         Native Apps

Select "Native" for client applications that are installed locally on a device. This setting is used for OAuth public native clients.

Register your App by clicking New Application Registration Button. A popup window like below will be visible and Fill the required items and select the application type as per your requirement.


The application will visible like the below screenshot after creating the process completely.




Now click on Application for detail. Please check the below screenshot.


 Application Owner

Add only if you want to make someone an owner. Otherwise, skip the steps.

 Application Permission

Below is the permission which is required to activate.






Following are the further detail of each permission. Please check the below screenshot.








Keys


For Web API we need a secret key with the help of this key client will get the Authentication.

After generation of the key, please save the key because it will not visible again to you.




Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...