HttpWebRequestMgt.GetResponse coming as Blank

Stivan_dsouza21
Member Posts: 218
Below is the POST request which i am sending and But Response is coming as blank. When i am Testing the URL in SOAP i getting the Response (Attachment attached) but in below code i am getting blank response. Can anyone let me know why i am receiving Blank Response.
URL1:='https://esb.admtl.com/service/PartnerFlightInquiry/v1/';
HttpWebRequestMgt.Initialize(URL1);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetContentType('text/xml');
HttpWebRequestMgt.SetReturnType('text/xml');
MSG :=
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:types.partnerflight.inquiry.fids.ops.service.admtl.com/v1" xmlns:v11="urn:shared.service.domain.admtl.com/v1">'+
'<soapenv:Header/>'+
'<soapenv:Body>'+
'<v1:GetFlightsRequest locale="" timezone="" pageStartIndex="1" pageMaxItems="0" enablePartialMatch="false">'+
'<v1:FlightStartDate>${=cal = java.util.Calendar.getInstance();dfUTC = new java.text.SimpleDateFormat("yyyy-MM-dd");'+
'dfUTC.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));dfUTC.format(cal.getTime());}</v1:FlightStartDate>'+
'<v1:FlightEndDate>${=cal = java.util.Calendar.getInstance();cal.add( java.util.Calendar.HOUR,168);dfUTC = new java.text.SimpleDateFormat("yyyy-MM-dd");'+
'dfUTC.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));dfUTC.format(cal.getTime());}</v1:FlightEndDate>'+
'<v1:ArrivalOrDeparture>DEPARTURE</v1:ArrivalOrDeparture>'+
'<!--Optional:'+
'<v1:AirlineIataCode>?</v1:AirlineIataCode>'+
'<v1:AirlineDisplayName>?</v1:AirlineDisplayName>'+
'<v1:AirportIataCode>?</v1:AirportIataCode>'+
'<v1:AirportName>?</v1:AirportName>'+
'<v1:FlightStartDate>?</v1:FlightStartDate>'+
'<v1:FlightEndDate>?</v1:FlightEndDate>'+
'<v1:FlightNumber>?</v1:FlightNumber>'+
'<v1:ArrivalOrDeparture>?</v1:ArrivalOrDeparture>'+
'<v1:TerminalSectorCode>?</v1:TerminalSectorCode>'+
'<v1:TerminalGate>?</v1:TerminalGate>'+
'<v1:TerminalStand>?</v1:TerminalStand>'+
'<v1:TerminalBelt>?</v1:TerminalBelt>'+
'<v1:AircraftTypeIataCode>?</v1:AircraftTypeIataCode>'+
'<v1:IataServiceTypeCode>?</v1:IataServiceTypeCode>'+
'<v1:AircraftRegistrationNumber>?</v1:AircraftRegistrationNumber>'+
'-->'+'</v1:GetFlightsRequest>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
HttpWebRequestMgt.AddBodyAsText(MSG);
MESSAGE(MSG);
TempBlob.INIT;
TempBlob.Blob.CREATEINSTREAM(instr);
IF HttpWebRequestMgt.GetResponse(instr,HttpStatusCode,ResponseHeaders) THEN BEGIN
MESSAGE('httpstatuscode : '+HttpStatusCode.ToString);
MESSAGE(ResponseHeaders.ToString);
APIRESULT := TempBlob.ReadAsText('',TEXTENCODING::UTF8);
MESSAGE(APIRESULT);
END;
Thanks in Advance
URL1:='https://esb.admtl.com/service/PartnerFlightInquiry/v1/';
HttpWebRequestMgt.Initialize(URL1);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetContentType('text/xml');
HttpWebRequestMgt.SetReturnType('text/xml');
MSG :=
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:types.partnerflight.inquiry.fids.ops.service.admtl.com/v1" xmlns:v11="urn:shared.service.domain.admtl.com/v1">'+
'<soapenv:Header/>'+
'<soapenv:Body>'+
'<v1:GetFlightsRequest locale="" timezone="" pageStartIndex="1" pageMaxItems="0" enablePartialMatch="false">'+
'<v1:FlightStartDate>${=cal = java.util.Calendar.getInstance();dfUTC = new java.text.SimpleDateFormat("yyyy-MM-dd");'+
'dfUTC.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));dfUTC.format(cal.getTime());}</v1:FlightStartDate>'+
'<v1:FlightEndDate>${=cal = java.util.Calendar.getInstance();cal.add( java.util.Calendar.HOUR,168);dfUTC = new java.text.SimpleDateFormat("yyyy-MM-dd");'+
'dfUTC.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));dfUTC.format(cal.getTime());}</v1:FlightEndDate>'+
'<v1:ArrivalOrDeparture>DEPARTURE</v1:ArrivalOrDeparture>'+
'<!--Optional:'+
'<v1:AirlineIataCode>?</v1:AirlineIataCode>'+
'<v1:AirlineDisplayName>?</v1:AirlineDisplayName>'+
'<v1:AirportIataCode>?</v1:AirportIataCode>'+
'<v1:AirportName>?</v1:AirportName>'+
'<v1:FlightStartDate>?</v1:FlightStartDate>'+
'<v1:FlightEndDate>?</v1:FlightEndDate>'+
'<v1:FlightNumber>?</v1:FlightNumber>'+
'<v1:ArrivalOrDeparture>?</v1:ArrivalOrDeparture>'+
'<v1:TerminalSectorCode>?</v1:TerminalSectorCode>'+
'<v1:TerminalGate>?</v1:TerminalGate>'+
'<v1:TerminalStand>?</v1:TerminalStand>'+
'<v1:TerminalBelt>?</v1:TerminalBelt>'+
'<v1:AircraftTypeIataCode>?</v1:AircraftTypeIataCode>'+
'<v1:IataServiceTypeCode>?</v1:IataServiceTypeCode>'+
'<v1:AircraftRegistrationNumber>?</v1:AircraftRegistrationNumber>'+
'-->'+'</v1:GetFlightsRequest>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
HttpWebRequestMgt.AddBodyAsText(MSG);
MESSAGE(MSG);
TempBlob.INIT;
TempBlob.Blob.CREATEINSTREAM(instr);
IF HttpWebRequestMgt.GetResponse(instr,HttpStatusCode,ResponseHeaders) THEN BEGIN
MESSAGE('httpstatuscode : '+HttpStatusCode.ToString);
MESSAGE(ResponseHeaders.ToString);
APIRESULT := TempBlob.ReadAsText('',TEXTENCODING::UTF8);
MESSAGE(APIRESULT);
END;
Thanks in Advance
Thanks & Regards,
Stivan D'souza
Stivan D'souza
0
Answers
-
Hello @Stivan_dsouza21 ,
Are you sending the MSG as you posted ?, because if that it's the case you need to get rid of the java calls in FlightStartDate and FlightEndDate and pass these dates in the expected format.
Also you can delete all the optional tags with the ? value.
Regards.0 -
Till its giving blank repsonse
FlightStartDate := 010119D;
EVALUATE(FlightStartTime,'00:00:01');
FlightEndDate := 310119D;
EVALUATE(FlightEndTime,'23:59:59');
URL1:='https://esb.admtl.com/service/PartnerFlightInquiry/v1/';
HttpWebRequestMgt.Initialize(URL1);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetContentType('text/xml');
HttpWebRequestMgt.SetReturnType('text/xml');
MSG :=
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:types.partnerflight.inquiry.fids.ops.service.admtl.com/v1" xmlns:v11="urn:shared.service.domain.admtl.com/v1">'+
'<soapenv:Header/>'+
'<soapenv:Body>'+
'<v1:GetFlightsRequest locale="" timezone="" pageStartIndex="1" pageMaxItems="0" enablePartialMatch="false">'+
'<v1:FlightStartDate>'+FORMAT(FlightStartDate,0,'<Year4>-<Month,2>-<DAY,2>')+' '+FORMAT(FlightStartTime,0,'<Hours24,2>:<Minutes,2>:<Seconds,2>')+'</v1:FlightStartDate>'+
'<v1:FlightEndDate>'+FORMAT(FlightEndDate,0,'<Year4>-<Month,2>-<DAY,2>')+' '+FORMAT(FlightEndTime,0,'<Hours24,2>:<Minutes,2>:<Seconds,2>')+'</v1:FlightEndDate>'+
'<v1:ArrivalOrDeparture>DEPARTURE</v1:ArrivalOrDeparture>'+
'<!--Optional:'+
'<v1:AirlineIataCode>?</v1:AirlineIataCode>'+
'<v1:AirlineDisplayName>?</v1:AirlineDisplayName>'+
'<v1:AirportIataCode>?</v1:AirportIataCode>'+
'<v1:AirportName>?</v1:AirportName>'+
'<v1:FlightStartDate>?</v1:FlightStartDate>'+
'<v1:FlightEndDate>?</v1:FlightEndDate>'+
'<v1:FlightNumber>?</v1:FlightNumber>'+
'<v1:ArrivalOrDeparture>?</v1:ArrivalOrDeparture>'+
'<v1:TerminalSectorCode>?</v1:TerminalSectorCode>'+
'<v1:TerminalGate>?</v1:TerminalGate>'+
'<v1:TerminalStand>?</v1:TerminalStand>'+
'<v1:TerminalBelt>?</v1:TerminalBelt>'+
'<v1:AircraftTypeIataCode>?</v1:AircraftTypeIataCode>'+
'<v1:IataServiceTypeCode>?</v1:IataServiceTypeCode>'+
'<v1:AircraftRegistrationNumber>?</v1:AircraftRegistrationNumber>'+
'-->'+'</v1:GetFlightsRequest>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
HttpWebRequestMgt.AddBodyAsText(MSG);
MESSAGE(MSG);
TempBlob.INIT;
TempBlob.Blob.CREATEINSTREAM(instr);
MESSAGE('%1',TempBlob.Blob);
IF HttpWebRequestMgt.GetResponse(instr,HttpStatusCode,ResponseHeaders) THEN BEGIN
MESSAGE('httpstatuscode : '+HttpStatusCode.ToString);
MESSAGE(ResponseHeaders.ToString);
APIRESULT := TempBlob.ReadAsText('',TEXTENCODING::UTF8);
MESSAGE(APIRESULT);
END;Thanks & Regards,
Stivan D'souza0 -
Hello @Stivan_dsouza21 ,
Try this and if it works to you then replace the vars URL, XMLReq and soapAction with your values and test it.OBJECT Codeunit 50000 WebService Call { OBJECT-PROPERTIES { Date=13/03/19; Time=20:44:18; Modified=Yes; Version List=WS; } PROPERTIES { OnRun=BEGIN WSCall; END; } CODE { PROCEDURE WSCall@1000000017(); VAR Request@1000000023 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest"; Response@1000000022 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse"; stream@1000000004 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StreamWriter"; ascii@1000000005 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.Encoding"; URL@1000000020 : Text[250]; XMLReq@1000000003 : Text; soapAction@1000000002 : Text; reader@1000000010 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlTextReader"; document@1000000009 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument"; ToFile@1000000006 : Text; FileMgt@1000000008 : Codeunit 419; FileSrv@1000000007 : Text; BEGIN URL := 'http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx'; soapAction := '"http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForYear"'; XMLReq := STRSUBSTNO('<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>'+ '<GetHolidaysForYear xmlns="http://www.holidaywebservice.com/HolidayService_v2/">'+ '<countryCode>%1</countryCode>'+ '<year>%2</year>'+ '</GetHolidaysForYear>'+ '</soap:Body></soap:Envelope>', 'UnitedStates', '2019'); Request := Request.HttpWebRequest; Request := Request.Create(URL); Request.Method('POST'); Request.ContentType('text/xml'); Request.Headers.Add('SOAPAction', soapAction); Request.Timeout := 120000; // Send the request to the webservice stream := stream.StreamWriter(Request.GetRequestStream(), ascii.UTF8); stream.Write(XMLReq); stream.Close(); // Get the response Response := Request.GetResponse(); reader := reader.XmlTextReader(Response.GetResponseStream()); // Save the response to a XML document := document.XmlDocument(); document.Load(reader); FileSrv := FileMgt.ServerTempFileName('xml'); document.Save(FileSrv); // Get from the server ToFile := FileMgt.ClientTempFileName('xml'); FileMgt.DownloadToFile(FileSrv, ToFile); // Show the response XML HYPERLINK(ToFile); END; BEGIN END. } }
Regards0 -
Hi ftornero,
i tired using your logic, but it gave the below mentioned error
Microsoft Dynamics NAV
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (404) Not Found.
OK
OBJECT Codeunit 50109 WebService Call
{
OBJECT-PROPERTIES
{
Date=14/03/19;
Time=08:05:24;
Modified=Yes;
Version List=WS;
}
PROPERTIES
{
OnRun=BEGIN
WSCall;
END;
}
CODE
{
PROCEDURE WSCall@1000000017();
VAR
Request@1000000023 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest";
Response@1000000022 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse";
stream@1000000004 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StreamWriter";
ascii@1000000005 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.Encoding";
URL@1000000020 : Text[250];
XMLReq@1000000003 : Text;
soapAction@1000000002 : Text;
reader@1000000010 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlTextReader";
document@1000000009 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
ToFile@1000000006 : Text;
FileMgt@1000000008 : Codeunit 419;
FileSrv@1000000007 : Text;
BEGIN
URL := 'https://esb.admtl.com/service/PartnerFlightInquiry/v1/';
soapAction := 'https://esb.admtl.com/service/PartnerFlightInquiry/v1/';
XMLReq := STRSUBSTNO(
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:types.partnerflight.inquiry.fids.ops.service.admtl.com/v1" xmlns:v11="urn:shared.service.domain.admtl.com/v1">'+
'<soapenv:Header/>'+
'<soapenv:Body>'+
'<v1:GetFlightsRequest locale="" timezone="" pageStartIndex="1" pageMaxItems="0" enablePartialMatch="false">'+
'<v1:FlightStartDate>${=cal = java.util.Calendar.getInstance();dfUTC = new java.text.SimpleDateFormat("yyyy-MM-dd");'+
'dfUTC.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));dfUTC.format(cal.getTime());}</v1:FlightStartDate>'+
'<v1:FlightEndDate>${=cal = java.util.Calendar.getInstance();cal.add( java.util.Calendar.HOUR,168);dfUTC = new java.text.SimpleDateFormat("yyyy-MM-dd");'+
'dfUTC.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));dfUTC.format(cal.getTime());}</v1:FlightEndDate>'+
'<v1:ArrivalOrDeparture>DEPARTURE</v1:ArrivalOrDeparture>'+
{
'<!--Optional:'+
'<v1:AirlineIataCode>?</v1:AirlineIataCode>'+
'<v1:AirlineDisplayName>?</v1:AirlineDisplayName>'+
'<v1:AirportIataCode>?</v1:AirportIataCode>'+
'<v1:AirportName>?</v1:AirportName>'+
'<v1:FlightStartDate>?</v1:FlightStartDate>'+
'<v1:FlightEndDate>?</v1:FlightEndDate>'+
'<v1:FlightNumber>?</v1:FlightNumber>'+
'<v1:ArrivalOrDeparture>?</v1:ArrivalOrDeparture>'+
'<v1:TerminalSectorCode>?</v1:TerminalSectorCode>'+
'<v1:TerminalGate>?</v1:TerminalGate>'+
'<v1:TerminalStand>?</v1:TerminalStand>'+
'<v1:TerminalBelt>?</v1:TerminalBelt>'+
'<v1:AircraftTypeIataCode>?</v1:AircraftTypeIataCode>'+
'<v1:IataServiceTypeCode>?</v1:IataServiceTypeCode>'+
'<v1:AircraftRegistrationNumber>?</v1:AircraftRegistrationNumber>'+
'-->'+
}
'</v1:GetFlightsRequest>'+
'</soapenv:Body>'+
'</soapenv:Envelope>');
Request := Request.HttpWebRequest;
Request := Request.Create(URL);
Request.Method('POST');
Request.ContentType('text/xml');
Request.Headers.Add('SOAPAction', soapAction);
Request.Timeout := 120000;
// Send the request to the webservice
stream := stream.StreamWriter(Request.GetRequestStream(), ascii.UTF8);
stream.Write(XMLReq);
stream.Close();
// Get the response
Response := Request.GetResponse();
reader := reader.XmlTextReader(Response.GetResponseStream());
// Save the response to a XML
document := document.XmlDocument();
document.Load(reader);
FileSrv := FileMgt.ServerTempFileName('xml');
document.Save(FileSrv);
// Get from the server
ToFile := FileMgt.ClientTempFileName('xml');
FileMgt.DownloadToFile(FileSrv, ToFile);
// Show the response XML
HYPERLINK(ToFile);
END;
BEGIN
END.
}
}
Thanks & Regards,
Stivan D'souza0 -
Hello @Stivan_dsouza21 ,
Did my example work in your machine ?
The error message seems that it is related to not reaching the remote server, could you test if with other means you do it ?.
Regards0 -
Hi Ftornero,
You example worked in my Machine. But by using My Urls still getting the same error.
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (404) Not Found.
Thanks & Regards,
Stivan D'souza0 -
Hello @Stivan_dsouza21,
I can see in the image that you provided that you are using SopaUI to test the web service and that there is some additional information that you put in the Header.
Is the test with SopaUI in the same machine that the test with NAV ?
Regards.0 -
Hi all,
Facing an error while sending date
Internal Server Error Test 500 response
The initial value '2019-03-26T09:01:41' is not valid with respect to the simple type definition '{http://www.w3.org/2001/XMLSchema}date'.
The initial value '2019-03-26T09:01:41' is not valid with respect to the simple type definition '{http://www.w3.org/2001/XMLSchema}date'.
Data sample sent
v1:FlightStartDate>2019-03-26T09:01:41</v1:FlightStartDate><
v1:FlightEndDate>2019-03-26T09:01:41</v1:FlightEndDate><
v1:ArrivalOrDeparture>DEPARTURE</v1:ArrivalOrDeparture><Thanks & Regards,
Stivan D'souza0 -
0
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