Import XML throught XMLport from .NET XmlDocument

drstakzdrstakz Member Posts: 30
edited 2015-02-19 in NAV Three Tier
Hi!
Pls, I have codeunit with external add-on (dotnet variable) which returning some XmlDocument (next dotnet var.). I want import this XML throught XMLport to database. But I don't want use file system for save xml to disk and read it back to NAV (at 21th century).

My idea is load XML to XmlDocument and write it to MemoryStream and this stream hand over to xmlPort for import.

but i have problem with convert .net stream to "nav" stream:
Break On Error Message:
Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavDotNet to Microsoft.Dynamics.Nav.Runtime.NavOutStream.
My code is:
xmlResponse := xmlResponse.XmlDocument();
MyAddon.GetXml(xmlResponse); // xmlResponse is "out XmlDocument"
// xmlResponse.Save('C:\..\someFile.xml'); // this working

MemoryStream := MemoryStream.MemoryStream();
xmlResponse.Save(MemoryStream);

COPYSTREAM(MemoryStream, InStream); // this not working, error message above
MyXmlPort.SETSOURCE(InStream);
MyXmlPort.IMPORT;
I try convert MemoryStream to OutStream with blob, but without success.
  TempBLOB.INIT;
  TempBLOB.Blob.CREATEOUTSTREAM(OutStream);
 
  //MemoryStream.Flush();
  //MemoryStream.Position := 0; 
  MemoryStream.CopyTo(OutStream); // I try also .WriteTo(..) -> both case make error

  COPYSTREAM(OutStream, InStream);

Some ideas?
Thanks!

Comments

  • vremeni4vremeni4 Member Posts: 323
    Hi,

    I assume this is NAV 2013 R2, as you did not say what NAV version it is.
    If this is the case take a look at the XMLport 9170 "Profile Import/Export".
    IF PageMetadata.LENGTH > 0 THEN BEGIN
      // OutStream cannot be used directly as it would write the input (metadata blob) as OEM even though it is stored as UTF-8 causing problems for characters not in OEM.
      // .Net StreamWriter can correctly write UTF-8.
      "Profile Metadata"."Page Metadata Delta".CREATEOUTSTREAM(MetadataOutStream);
      streamWriter := streamWriter.StreamWriter(MetadataOutStream,Encoding.UTF8);
      streamWriter.Write(PageMetadata);
    END;
    
    If that does not help take a look at this code example for FTP that uses streams
    http://www.mibuso.com/forum/viewtopic.php?f=7&t=58425&hilit=FTP

    I hope this helps.
    Thanks.
  • drstakz Did you ever find a solution for this?
Sign In or Register to comment.