I am building an asp.net website that communicates with NAV via Web Services.  One of the issues I had to solve was the authentication between the web and the NAV Web Services.

You can ether use NTLM authentication or the current user.  If you will be using NTLM you will need code similar to this in you website.
[code htmlscript=”false” land=”vb”]Dim NAVPunch1 As New WebService.NAVPunch
Dim User As New System.Net.NetworkCredential
User.Domain = "Dynamics.is"
User.UserName = "Gunnar"
User.Password = "<password>"
NAVPunch1.Credentials = User
NAVPunch1.Url = "http://Dynamics.is:7047/DynamicsNAV/WS/" & _
"Dynamics/Codeunit/NAVPunch"[/code]
This also means that you have to store the username, domain and password in you web site code. You will also need to enable NTLM authentication in your CustomSettings.xml
[code htmlscript=”false” lang=”vb”]<add key="WebServicesUseNTLMAuthentication" value="true"></add>[/code]
The other way is to use the credentials of the user running the web. In that case the code would be similar to this:
[code htmlscript=”false” lang=”vb”]NAVPunch1.UseDefaultCredentials = True
NAVPunch1.Url = "http://Dynamics.is:7047/DynamicsNAV/WS/" & _
"Dynamics/Codeunit/NAVPunch"[/code]
And no changes to CustomSettings.xml are required.  The authentication will be handled with IIS.  You will need to go into Internet Information Services (IIS) Manager.  Go into Application Pools and add a new application pool

Select a name that fits you web site and then go to Advanced Settings…

and update the Idendity.

Then go and select this Application Pool for the web site.

The final step is to make sure that the user you select in your code or in the application pool has access to NAV Web Services.  That is done with the standard authentication methods in Dynamics NAV.

10 thoughts on “My asp.net website using NAV Web Service

  1. Hi Gunnar

    That’s a great tip on storing the credentials on the App Pool!
    Thanks alot!

    Kind regards
    Søren

    1. Glad to help,
      Regards,
      Gunnar Þór.

  2. Per says:

    Thanks a lot. I had been searching for hours before I found your above tip. Works great.

    Cheers from Danmark,
    Per

  3. Karan says:

    hey i want to use web services of naviosion 2013 so can u tell me plz

    thanks

    Karan

    1. I don’t follow Karan. Can you be more specific ?

  4. Marc says:

    Hi, great tip, however, can I ask if it is possible to get the current Windows user that is logged into the website?

    For example, my web service returns data based on the USERID in NAV, but if I set a user in the apppool it will always return data for that particular user.

    I want it to return the data dependent on the Windows user that is logged into the website, almost so IIS passes through the WIndows Account.

    Thanks,
    Marc

    1. Ian Silvers says:

      Hi Marc

      Did you manage to find a solution for this? we are running into the same problem, and do not seem to be able to bypass this.

      Thanks

      1. I would think that you need to use a single user to connect to NAV. However, you can easilly pass the current user as a parameter in the Web Service and handle that userid in NAV.

        1. Ian Silvers says:

          Thanks Gunnar. That is what I was expecting, but it would be so much easier if I could get the login directly from the website.

  5. Marc says:

    Hi Ian,

    Not sure if it is a similar problem but I hope it helps a little:

    The site we developed used NAV2009 R2 and was an intranet site that used the “UseDefaultCredentials = true;” command described above to pass the current Windows users credentials through to NAV.

    The problem was that when using the DefaultAppPool I kept getting 403 unauthorised errors, however it worked when the site was run locally on the server. Turns out we had setup delegation from the NAV server to the SQL server (as per 3-tiers on 3 computers MSDN article) but delegation was also required to be setup so the credential could be passed from the web server where IIS was running to the middle-tier.

    Seems to work now in our test environment using Kerberos (NTLM flag is set to false).

    Thanks,
    Marc

Leave a Reply

%d bloggers like this: