Calling NAV Web Service from JavaScript

Cyberghost
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/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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
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/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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!"
"God and developers are in a constant battle. Developments to make their applications more idiot-proof, and God to produce bigger idiots!"
0
Answers
-
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?0 -
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!"0 -
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 well0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions