Consuming NAV web service through NAV - error 401

AKAK Member Posts: 226
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

Sign In or Register to comment.