Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Send XMLPORT from one NAV DB to another with Webservice

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?

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Send XMLPORT from one NAV DB to another with Webservice

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans