web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Send XMLPORT from one NAV DB to another with Webservice

(0) ShareShare
ReportReport
Posted on by 10

Hello

We are using NAV 2017. We have two NAV DB's on two different Servers but same Domain. I want to send XMLPORT data to the other Navision with a webservice. I can't make a GET on the other DB. I need to make a POST or something.

NAV1 = Navision Company which sends date.

NAV2 = Navision Company which should receive the data

On NAV2 I created a Codeunit with Function saveXML(). This Codeunit I created an entry on the table "Web service" and published it.

On NAV1 I have a XMLPORT which I want to send to the function saveXML(). I want to do this with a webservice but I don't know how to call the function excatly. I can call the servicename from the Codeunit and receive ResponseMessage 200 OK. But nothing happens because I also need to call the FUNCTION not only the CODEUNIT.

I tried to add :codeunitfunctionname at the end of uri but then I receive status code 500 internal error and on the event viewer ServiceBrokerException "servicename:codeunitfunction" not found

Here is the Code from NAV1:

tempBlob.DELETEALL;
tempBlob."Primary Key" := 1;
tempBlob.INSERT;
tempBlob.Blob.CREATEOUTSTREAM(OutStr,TEXTENCODING::UTF16);
ICXML.SETTABLEVIEW(pICShip);
ICXML.SETDESTINATION(OutStr);
ICXML.FILENAME('test.XML');
ICXML.EXPORT();
tempBlob.MODIFY;

IF NOT tempBlob.Blob.HASVALUE() THEN
EXIT;

tempBlob.CALCFIELDS(Blob);
tempBlob.Blob.CREATEINSTREAM(InStr);
InStr.READTEXT(txtResult);

WHILE NOT InStr.EOS() DO BEGIN
InStr.READTEXT(Line);
txtResult += Line;
END;

Uri := Uri.Uri('servername:port/instance/WS/companyname/Codeunit/servicename:codeunitfunctionname');
HttpHandler := HttpHandler.HttpClientHandler;
NCredentials := NCredentials.NetworkCredential(username, password);
HttpHandler.Credentials(NCredentials);
HttpClient := HttpClient.HttpClient(HttpHandler);
StringContent := StringContent.StringContent(txtResult,Encoding.UTF8,'application/xml');

ResponseMessage := HttpClient.PostAsync(Uri,StringContent).Result;

And here the function from NAV2:

saveXML(pXmlUpdateIn : Text)
lFile.CREATE(filename);
lFile.CREATEOUTSTREAM(Outstr);
Outstr.WRITETEXT(pXmlUpdateIn);

Maybe there is another way to send this with webservice than with the code from NAV1 but I dont find any? Especially for sending the data to the FUNCTION in the codeunit.

Can somebody help me please?

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,184 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,148 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 677

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans