Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Certificate issue while sending a file through HTTP in ax 2012

(0) ShareShare
ReportReport
Posted on by 250

Hi,

I am trying to send a file to third party URL through 'System.Net.HttpWebRequest' in Ax 2012.

When system reaches the place 'response = request.GetResponse();', I am getting the error 'The remote certificate is invalid according to the validation procedure.'.

I have installed respective third party certificate still i am getting the above error.

Below is my job,

CLRObject                                   clrObj;
str                                                 destinationUrl;

System.Net.HttpWebRequest      request;

System.Net.HttpWebResponse   response;

System.IO.Stream                        requestStream, responseStream;
System.IO.StreamReader            streamReader;
System.Exception                         exception;

try
{
       new InteropPermission(InteropKind::ClrInterop).assert();
       clrObj = System.Net.WebRequest::Create(destinationUrl);
       request = clrObj;
       request.set_Method("GET");
       response = request.GetResponse();
       responseStream = response.GetResponseStream();
       streamReader = new System.IO.StreamReader(responseStream);
       responseXml = streamReader.ReadToEnd();
       info(responseXml);
}
catch (Exception::CLRError)
{
       exception = CLRInterop::getLastException().GetBaseException();
       error(exception.get_Message());
}

In order to bypass this error i am trying to write the below code.

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; // **** Always accept
};

Issue: I am not able to get the property of 'ServerCertificateValidationCallback ' from the class 'System.Net.ServicePointManager' as its throwing syntax error.

 

Anybody faced this issue before?  Kindly help me to fix either of the issue.

Note: I am able to access the URL through Internet explorer by clicking 'continue to this website' option.

pastedimage1592226605360v1.png

Ax versions: AX 2012 R3,

.Net framework version: 4.5.1

  • Manikanda Gopal Profile Picture
    Manikanda Gopal 250 on at
    RE: Certificate issue while sending a file through HTTP in ax 2012

    Applogies for the late reply.

    Thanks for your suggestion Martin, Yea I will post in .NET forums regarding .NET APIs.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,340 Most Valuable Professional on at
    RE: Certificate issue while sending a file through HTTP in ax 2012

    Your code with "delegate" is indeed invalid. It's not X++ at all; it seems you took a piece if C# and you're trying to use it as if it was X++. Create a C# class library, move all your code there and add the project to AOT and then use your library from X++.

    By the way, when you have problems with using .NET APIs, consider asking in .NET forums (and here discuss things specific to Dynamics AX).

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,602 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,340 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans