Options

Passing credentials to external web service

arnhembarnhemb Member Posts: 9
edited 2012-02-16 in NAV Three Tier
Hi All,

I am calling a web service from within Nav that requires authentication (username and password) to access. How does one send the username and password with the request in order to prevent the authentication dialog popping up to the user.

I call like web service like this, setting AuthUser and AuthPassword on the header, but this seems to make no difference:
CREATE(autXmlHttp);
autXmlHttp.open('POST', txtServiceURI, 0);
autXmlHttp.setRequestHeader('Content-type', 'text/xml');
autXmlHttp.setRequestHeader('AuthUser', txtUserName);
autXmlHttp.setRequestHeader('AuthPassword', txtPassword);
autXmlHttp.setRequestHeader('SOAPAction', txtServiceAction);
autXmlHttp.setRequestHeader('Timeout', FORMAT(intTimeout));
autXmlHttp.send(autXmlDoc);
Any ideas?

Comments

  • Options
    kinekine Member Posts: 12,562
    Depends on if the the user name and password should be same as the user under which it is called or not. If yes, you can try to add the target URL into Extranet URLs list in Internet Explorer to allow automatic credential transfer, but all depends on the infrastructure and authentication type of the target webservice.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    arnhembarnhemb Member Posts: 9
    Thanks for the reply, but in this case the username and password is the same irrespective of logged in user.

    EDIT: and excuse the late response. Did not realise I was not subscribed to the post.
  • Options
    kinekine Member Posts: 12,562
    If you call webservices, which are using Windows authentication, I think that the credentials (or ticket) will be passed automatically, if the target URL is in Intranet zone in Internet Explorer.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    arnhembarnhemb Member Posts: 9
    Still any idea of how to pass credentials explicitly then?
  • Options
    kinekine Member Posts: 12,562
    Look at all parameters of the Open function you are using... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    arnhembarnhemb Member Posts: 9
    Ah, right there all the time :whistle: . I was so convinced the answer lay in the header.

    Just for those of you who enjoy NAV's lack of intellisense:
    autXmlHttp.open(BSTR bstrMethod, BSTR bstrURL[, VARIANT varAsync][, VARIANT bstrUser][, VARIANT bstrPassword]

    Thanks a lot, appreciate it.
  • Options
    kinekine Member Posts: 12,562
    You are welcome!
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.