Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Problem getting webservice response

Posted on by Microsoft Employee

Hi everyone,

First of all, the Webservice it's tested with the SOAP:UI, the response is ;

<data contentType="application/octet-stream" contentLength="88047">JVBERi0x.. A ENCODED PDF</data>

Then, I try to get this info to build a BigText and build my PDF document. I've tried in two different ways that are listed below;

FIRST OPTION

VARS :

HTTPRequest	DotNet	MSXML.XMLHTTPRequest.'Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	

CODE :

CLEAR(HTTPRequest);
HTTPRequest := HTTPRequestClass.XMLHTTPRequestClass;
HTTPRequest.open('POST', URL, FALSE,User,Password);
HTTPRequest.setRequestHeader('Content-Type', 'application/xml; charset=utf-8');


HTTPRequest.send(BIGTEXTOutPut); //Valid XML Structure inserted in to the BIGTEXTOutPut

IF NOT (HTTPRequest.status = 200) THEN
BEGIN
  InsertErrorLog(COPYSTR(FORMAT(HTTPRequest.status) + ' ' + FORMAT(HTTPRequest.statusText),1,250));
  ERROR(TEXTERRORCONSTANT);
END;


Now, I have three options to get the HTTPRequest response ;

responseStream --> Try to get the response in a System.IO.MemoryStream , have the chance to use the function CopyTo for copy it to a NAV InStream, and with my BigText read this inStream. When i use the CopyTo from the MemoryStream to a NAV inStream have an error. 

responseText --> The text from the response is so long that the RTC client have a unexpected error and the session closes.

responseXML --> The response don't have a valid estructure to load it in a XMLDoc var.

SECOND OPTION 

VARS : 
Credential	DotNet	System.Net.NetworkCredential.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
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'	
MemoryStream	DotNet	System.IO.MemoryStream.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
XMLDocNet	DotNet	System.Xml.XmlDocument.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	


CODE :
XMLDocNET := XMLDocNET.XmlDocument(); XMLDocNET.LoadXml(FORMAT(BIGTEXTOutPut)); //XMLDocNET.Save('C:\TEMP\RequestDotNet.xml'); HttpWebRequest := HttpWebRequest.Create(URL); HttpWebRequest.Timeout := 30000; HttpWebRequest.UseDefaultCredentials(FALSE); Credential := Credential.NetworkCredential; Credential.UserName := ValidUser; Credential.Password := ValidPW; HttpWebRequest.Credentials := Credential; HttpWebRequest.Method := 'POST'; HttpWebRequest.ContentType := 'application/xml; charset=utf-8'; MemoryStream := HttpWebRequest.GetRequestStream; XMLDocNET.Save(MemoryStream); MemoryStream.Flush; MemoryStream.Close; HttpWebResponse := HttpWebRequest.GetResponse; MemoryStream := HttpWebResponse.GetResponseStream; lRecTempBlob.Blob.CREATEINSTREAM(lInStream); lMemoryStream.WriteTo(lInStream); //After of that use BIGTEXT.READ for load lInstream

When i try to use WriteTo method, have an error converting to NAV inStream...

Any ideas?

Thank you!!

*This post is locked for comments

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Problem getting webservice response

    Please check this blog and see if it is helpful

    naverp.wordpress.com/.../webservice

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem getting webservice response

    Sorry suresh, for sure the HttpWebResponse it's loaded with that method. But continue getting that error..

    thanks!

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Problem getting webservice response

    Have you got the response from the request before that command

    HttpWebResponse := HttpWebRequest.GetResponse();

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem getting webservice response

    Hi Suresh,

    Thank you for your answer, Im try to do it like  ;

    Stream	DotNet	System.IO.Stream.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    
    
    Stream := HttpWebResponse.GetResponseStream();

    Error ;

    Cannot serialize an instance of the following .NET Framework object: assembly System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, type System.Net.ConnectStream.

    Any idea?

    Thank you!

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Problem getting webservice response

    You have to WriteTo Outstream or you can do something like this to get data into bigtext

    Stream is System.IO.Stream

    StreamReader is System.IO.StreamReader

    Stream := HttpWebResponse.GetResponseStream;
    StreamReader := StreamReader.StreamReader(Stream);
    bt.ADDTEXT(StreamReader.ReadToEnd);
    

    _Stream := _FtpWebResp.GetResponseStream;
          _StreamReader := _StreamReader.StreamReader(_Stream);
          _bt.ADDTEXT(_StreamReader.ReadToEnd);
    

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans