Error calling external webservice in nav 2018

dsrdev
Member Posts: 2
Hi all,
I am calling an external webservice from NAV with dotnet. I am using the same code in dynamics nav 2016 as in dynamics nav 2018, while in 2016 it's working nicely in 2018 it's giving me the following error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond
This error happens in the following line:
RequestStr := HttpWebRequest.GetRequestStream;
Apparently, it seems it's somtehing realted to dynamics nav 2018 but I can't find what it is, I will be very gratefull if someone could help me with any idea or tip to solve it.
The code:
Name DataType Subtype Length
HttpWebRequest DotNet System.Net.HttpWebRequest.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
HttpWebResponse DotNet System.Net.WebResponse.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
HttpStatusCode DotNet System.Net.HttpStatusCode.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
HttpWebException DotNet System.Net.WebException.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
NavWebRequest DotNet NAVWebRequest.NAVWebRequest.'NAVWebRequest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f53f0925d26e1382'
ServicePointManager DotNet System.Net.ServicePointManager.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
SecurityProtocol DotNet System.Net.SecurityProtocolType.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
WSmngt.SendRequestToApi(UrlLogin,'POST','application/x-www-form-urlencoded','application/json',TRUE,'gestor','SGS',
'Cache-Control','no-cache','username=&password=&grant_type=password');
AuthToken := GetResponseValue('access_token');
SendRequestToApi(Url : Text;Method : Text;ContentType : Text;ReturnType : Text;DisableUI : Boolean;HeaderKey1 : Text;HeaderValue1 : Text;HeaderKey2 : Text;HeaderValue2 : Text;BodyText : Text)
//inicializa la conexión y envía la petición
InitConnection(HttpWebRequest,Url,Method,ContentType,ReturnType,DisableUI);
IF HeaderKey1 <> '' THEN
AddHeader(HttpWebRequest,HeaderKey1,HeaderValue1);
IF HeaderKey2 <> '' THEN
AddHeader(HttpWebRequest,HeaderKey2,HeaderValue2);
AddBody(HttpWebRequest,BodyText);
DoWebRequest(HttpWebRequest,HttpWebResponse,'');
InitConnection(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";PostUrl : Text;Method : Text;ContentType : Text;ReturnType : Text;DisableUI : Boolean)
Uri := Uri.Uri(PostUrl);
HttpWebRequest := HttpWebRequest.Create(Uri);
IF DisableUI THEN
HttpWebRequestMgt.DisableUI;
HttpWebRequest.KeepAlive := FALSE;
HttpWebRequest.AllowAutoRedirect := TRUE;
HttpWebRequest.UseDefaultCredentials := TRUE;
HttpWebRequest.Timeout := 300000;
HttpWebRequest.Method := Method;
HttpWebRequest.ContentType := ContentType;
HttpWebRequest.Accept := ReturnType;
AddHeader(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";key : Text;value : Text)
HttpWebRequest.Headers.Add(key,value);
AddBody(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";XmlBodyText : Text)
RequestStr := HttpWebRequest.GetRequestStream;
StreamWriter := StreamWriter.StreamWriter(RequestStr,Encoding.UTF8);
StreamWriter.Write(XmlBodyText);
StreamWriter.Flush;
StreamWriter.Close;
StreamWriter.Dispose;
DoWebRequest(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";VAR HttpWebResponse : DotNet "System.Net.WebResponse";IgnoreCode : Code[10])
ServicePointManager.SecurityProtocol(SecurityProtocol.Tls);
NAVWebRequest := NAVWebRequest.NAVWebRequest;
IF NOT NAVWebRequest.doRequest(HttpWebRequest,HttpWebException,HttpWebResponse) THEN
IF (IgnoreCode = '') OR (STRPOS(HttpWebException.Message,IgnoreCode) = 0) THEN
ERROR(HttpWebRequestError,HttpWebException.Status.ToString,HttpWebException.Message);
I am calling an external webservice from NAV with dotnet. I am using the same code in dynamics nav 2016 as in dynamics nav 2018, while in 2016 it's working nicely in 2018 it's giving me the following error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond
This error happens in the following line:
RequestStr := HttpWebRequest.GetRequestStream;
Apparently, it seems it's somtehing realted to dynamics nav 2018 but I can't find what it is, I will be very gratefull if someone could help me with any idea or tip to solve it.
The code:
Name DataType Subtype Length
HttpWebRequest DotNet System.Net.HttpWebRequest.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
HttpWebResponse DotNet System.Net.WebResponse.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
HttpStatusCode DotNet System.Net.HttpStatusCode.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
HttpWebException DotNet System.Net.WebException.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
NavWebRequest DotNet NAVWebRequest.NAVWebRequest.'NAVWebRequest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f53f0925d26e1382'
ServicePointManager DotNet System.Net.ServicePointManager.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
SecurityProtocol DotNet System.Net.SecurityProtocolType.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
WSmngt.SendRequestToApi(UrlLogin,'POST','application/x-www-form-urlencoded','application/json',TRUE,'gestor','SGS',
'Cache-Control','no-cache','username=&password=&grant_type=password');
AuthToken := GetResponseValue('access_token');
SendRequestToApi(Url : Text;Method : Text;ContentType : Text;ReturnType : Text;DisableUI : Boolean;HeaderKey1 : Text;HeaderValue1 : Text;HeaderKey2 : Text;HeaderValue2 : Text;BodyText : Text)
//inicializa la conexión y envía la petición
InitConnection(HttpWebRequest,Url,Method,ContentType,ReturnType,DisableUI);
IF HeaderKey1 <> '' THEN
AddHeader(HttpWebRequest,HeaderKey1,HeaderValue1);
IF HeaderKey2 <> '' THEN
AddHeader(HttpWebRequest,HeaderKey2,HeaderValue2);
AddBody(HttpWebRequest,BodyText);
DoWebRequest(HttpWebRequest,HttpWebResponse,'');
InitConnection(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";PostUrl : Text;Method : Text;ContentType : Text;ReturnType : Text;DisableUI : Boolean)
Uri := Uri.Uri(PostUrl);
HttpWebRequest := HttpWebRequest.Create(Uri);
IF DisableUI THEN
HttpWebRequestMgt.DisableUI;
HttpWebRequest.KeepAlive := FALSE;
HttpWebRequest.AllowAutoRedirect := TRUE;
HttpWebRequest.UseDefaultCredentials := TRUE;
HttpWebRequest.Timeout := 300000;
HttpWebRequest.Method := Method;
HttpWebRequest.ContentType := ContentType;
HttpWebRequest.Accept := ReturnType;
AddHeader(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";key : Text;value : Text)
HttpWebRequest.Headers.Add(key,value);
AddBody(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";XmlBodyText : Text)
RequestStr := HttpWebRequest.GetRequestStream;
StreamWriter := StreamWriter.StreamWriter(RequestStr,Encoding.UTF8);
StreamWriter.Write(XmlBodyText);
StreamWriter.Flush;
StreamWriter.Close;
StreamWriter.Dispose;
DoWebRequest(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";VAR HttpWebResponse : DotNet "System.Net.WebResponse";IgnoreCode : Code[10])
ServicePointManager.SecurityProtocol(SecurityProtocol.Tls);
NAVWebRequest := NAVWebRequest.NAVWebRequest;
IF NOT NAVWebRequest.doRequest(HttpWebRequest,HttpWebException,HttpWebResponse) THEN
IF (IgnoreCode = '') OR (STRPOS(HttpWebException.Message,IgnoreCode) = 0) THEN
ERROR(HttpWebRequestError,HttpWebException.Status.ToString,HttpWebException.Message);
0
Answers
-
I have solved it: it was an error with the port I was using for the comunication.0
-
Hi
I've got the same error, what do you mean by :
it was an error with the port I was using for the comunication?
where do you setup this port?0 -
I believe if your IP is accessible from outside then its fine, How come Port Issue for this??Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
If I send my xml throught SoapUI, the connection is fine.
The error is only when I use
I do find why it doesn't work anymore?
It was fine before NAV 2018, in NAV 2017
0 -
500 means its unable to connect and it may have several reasons -
Check out this link
https://www.lifewire.com/500-internal-server-error-explained-2622938
Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
Thank you RockWithNAV,
I found a mistake in my URL, it gives this error.
So now, my problem is solved0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions