Calling NAV Web Service from JavaScript

CyberghostCyberghost Member Posts: 46
Hi all

I'm having a REALLY bad week so I'm hoping someone can help with this little frustration :-)

I'm trying to write a piece of JavaScript which calls a NAV Webservice. Now I've played about a lot with webservices but it's normally me calling them from NAV rather than calling a NAV one. On top of this, I don't really know JavaScript :-)

Anyway, I have a simple NAV webservice which adds a record to a table. I am trying to call it as a SOAP web service but don't mind if there's a better option such as OData. I have also tried both with windows logins and NAVUserPassword (https) and get the same error.

The error is:

Server instance: DynamicsNAV110CU1
Tenant: <ii>default</ii>
<ii>Session type: WebServiceClient
Session ID: 10
This licence is not compatible with this version of Dynamics NAV.</ii>


The html page is as follows:

<html>
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript">
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://xxx.xxx.co.uk:7047/DynamicsNAV110CU1/WS/Codeunit/BraintreeWebFunctions');

// build SOAP request
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
'<soap:Body><CreateCustomerPaymentNonce xmlns="urn:microsoft-dynamics-schemas/codeunit/BraintreeWebFunctions">' +
'<custID>WEB</custID>' +
'<nonce>Friday C</nonce>' +
'</CreateCustomerPaymentNonce>' +
'</soap:Body>' +
'</soap:Envelope>';

xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert('done. use firebug/console to see network response');
}
}
}
// Send the POST request
xmlhttp.setRequestHeader("Authorization", "Basic " + btoa("xxx.xxx@xxx.co.uk:xxx"));
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlhttp.withCredentials = true;
xmlhttp.send(sr);
// send request
// ...
}
</script>
</head>
<body>
Test
<form name="Demo" action="" method="post">
<div>
<input type="button" value="Soap" onclick="soap();" />
</div>
</form>
</body>
</html>


Now I've tried shorted Service Names and Database Names. It also works with Web Service Studio and I can run the RTC with no issues.

Anyone have any suggestions?

Cheers

Chris
"When you eliminate the impossible, whatever remains, however improbable, must be the truth" - Sherlock Holmes

"God and developers are in a constant battle. Developments to make their applications more idiot-proof, and God to produce bigger idiots!"

Answers

  • AKAK Member Posts: 226
    Since you get a licence error from NAV, you might want to check that the licence you have installed is the right one.
    I suppose you get the same error when calling the web service with something like WebServiceStudio?
  • CyberghostCyberghost Member Posts: 46
    Hi,

    It is definitely the right licence but I am getting another one downloaded to be 110% sure.

    Yes I get the same error with Web Service Studio but it adds the entry to the table as expected whereas the html page doesn't.

    Cheers

    Chris
    "When you eliminate the impossible, whatever remains, however improbable, must be the truth" - Sherlock Holmes

    "God and developers are in a constant battle. Developments to make their applications more idiot-proof, and God to produce bigger idiots!"
  • geronimogeronimo Member Posts: 90
    have you restarted the service after adding the license to the database?

    whenever i'm in doubt on connecting to a webservice i usually go back to the examples from freddy's blog

    the link for the javascript example:
    https://blogs.msdn.microsoft.com/freddyk/2010/01/21/connecting-to-nav-web-services-from-javascript/

    i'd suggest getting that one and checking if it works or gives a problem on license as well
Sign In or Register to comment.