Import XML throught XMLport from .NET XmlDocument

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!

Hello Zdenek,

No solution, I’m sorry… But rather the same problem… Did You find a solution to this?

Best regards

/Örjan

Hi, this problem I can no longer remember. :slight_smile: But I have in my research database similar solution. I consider that this works, only problem with encoding, this not properly resolved (Czech chars).

xmlResponse1 := xmlResponse1.XmlDocument();

IF Addon1.GetResponse(xmlResponse1) THEN BEGIN

CLEAR(BigText1);

BigText1.ADDTEXT(’<?xml version="1.0" encoding="windows-1250" ?>’); // DotNet addon return xmlDocument without this

BigText1.ADDTEXT(xmlResponse1.InnerXml);

Document1.Blob.CREATEOUTSTREAM(OutStream1); // Just as initialization, Document1 is Table 99008535

Document1.Blob.CREATEINSTREAM(InStream1); // Just as initialization, Document1 is Table 99008535

BigText1.WRITE(OutStream1);

COPYSTREAM(OutStream1, InStream1);

xmlPort1.SETSOURCE(InStream1);

IF xmlPort1.IMPORT THEN

MESSAGE(‘Data was succesfully imported’);

Hello Zdenek,

Thanks a lot for Your Quick feedback! I Will try this solution to my problem…

Best regards

/Örjan

Hey,

It might come to late, but for the people that will come and visit this forum searching for a solution to this problem that does not break the encoding try the following :

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

MyXmlPort.SETSOURCE(MemoryStream);
MyXmlPort.IMPORT;

From what I can see it works without having to Copy the DotNet Memory Stream to a OutStream, just send the MemoryStream to the XMLPort.

This was tested on Dynamics NAV 2013 R2.

Hope it helps .