web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Adding callback method...
Finance forum

Adding callback method for .net event in x++

(0) ShareShare
ReportReport
Posted on by 25

So the System.Net.ServicePointManager has the function, to add a callback method for the ServerCertificateValidationCallback method/event

I want to add my own callback method to this in x++.

The background is the following post, where this is appearently done in AX2012:

https://community.dynamics.com/ax/b/dynamicsax_wpfandnetinnovations/archive/2012/11/25/making-calls-to-secure-web-services

In AX 2012 it can be done the following way:

System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate(object sender,
                         System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                         System.Security.Cryptography.X509Certificates.X509Chain chain,
                         System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; };
This is not possible to do the same way in D365FO/AX7.
The += operator is only allowed with the eventhandler(...) pattern, not with delegate(...)
I have tried several takes, including trying to create a new System.Net.Security.RemoteCertificateValidationCallback object, but can't find a way to make it even compile.
Does anyone have experience with this?
I would prefer to keep the code in x++, and not having to make it in c#, but if that's the only option I may have to go for the red pill

Kind Regards

Tommy Axelgaard

  • Suggested answer
    Martin Dráb Profile Picture
    240,845 Most Valuable Professional on at

    You're wrong in thinking that the code above is X++. It's C# code using an anonymous function as an event handler; X++ doesn't have anything like that.

    Consume the service in a C# class library where you can do such things.

  • Blue Wang Profile Picture
    Microsoft Employee on at

    Hi Tommy,

     

    You can call methods in C# through X++.

    1. On your original project, add a new project (C# Class Library) and write your method

    2. Writing Event Handler Method

    3. In the original project, add references and point to the newly written C# class

    For more details, you can refer:

    https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/dev-tools/write-business-logic#handle-the-event-when-a-record-is-added

  • Martin Dráb Profile Picture
    240,845 Most Valuable Professional on at

    The link is about a different topic. It's about handling AX events in a .NET code, not handling .NET events in AX.

  • Benny.Gao Profile Picture
    5 on at

    There is solution resolved your problem. Pls refer to ahelper-d365fo.blogspot.com/.../x-code-ignore-ssl-certificate.html

    I've verified that it works.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans