I've created a simple NAV 2009 web service (SPNEGO authentication) and can access it with Webservice Studio when logged in at the NAV server. I've also some C/AL code to access the same web service, but when run in the classic client at the server, I get the "Http Error 401: Unauthorized" error.
The user running Webservice Studio and the classic client are the same, it is in fact the same session on the server. I can even access the web service from a different PC with a different user with Webservice Studio.
Relevant code (stolen from the download section):
IF ISCLEAR(XmlDoc) THEN
CREATE(XmlDoc);
IF ISCLEAR(XmlHttp) THEN
CREATE(XmlHttp);
XmlHttp.open('POST','http://996rzdb3:7047/MicrosoftDynamicsNAVServer/WS/'+OtherCompany+'/Codeunit/RunObject',0);
XmlHttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
XmlHttp.setRequestHeader('SOAPAction','RunObject');
XmlHttp.setTimeouts(10000,10000,10000,100000);
XmlHttp.send('<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body><RunObject xmlns="urn:microsoft-dynamics-schemas/codeunit/RunObject">' +
'<objectType>'+ObjectType+'</objectType><objectID>'+FORMAT(ObjectID)+'</objectID>'+
'</RunObject></soap:Body></soap:Envelope>');
IF XmlHttp.status <> 200 THEN
MESSAGE('Http Error ' + ' ' + FORMAT(XmlHttp.status) + ': ' + XmlHttp.statusText);
As far as I understand, when running the code in classic client, it will log on to the web service as the user who is logged into the client, right? And this also happens when using WebService Studio. The user should be the same in both cases, but it works only in the latter.
Has someone an idea what might be wrong?
Comments
The above code uses ServerXMLHTTP automation server, which doesn't use kerberos authentication by default (https://support.microsoft.com/en-us/help/314404/how-to-use-kerberos-with-the-serverxmlhttp-component-in-msxml).
If using XMLHTTP instead, it works as expected.