简体   繁体   中英

dynamics nav webservice error 401 Unauthorized

When consuming a dynamics nav web service I get the following error :

The request failed with HTTP status 401: Unauthorized.

However when I try it in a browser it works . I tried the following but its still not working :

service.UseDefaultCredentials = true;
service.PreAuthenticate = true;

also :

service.Credentials = new System.Net.NetworkCredential("XXXXX", "XXXX","XXXX");

I even tried using dynamics nav acces key but also it didn't work.

Any new suggestions ?

I know this thread is more than 4 years old, but i thought if somone is currently searching for this problem he will come across this trhead, like me.

There is currently a problem with NTLM and Xamarin (at the moment i write this, the problem also exists in .net core on MacOS).

See the links:

iOS: https://github.com/xamarin/xamarin-macios/issues/7770

Android: https://developercommunity.visualstudio.com/content/problem/756697/last-visual-studio-update-brakes-ntlm-authenticati.html

The solution is to use the "MonoWebRequestHandler". For a combined Android and iOS Solution check my latest post here

I hope i could save somones time with this post!

Several things might be wrong.

Did you check what kind of authentication the Service Tier is setup to? Is there a default company set (or are you selecting a company in the URL). Is NTLM on or off; these are all possible reasons this error might popup.

I think you're code should be like that

service.UseDefaultCredentials = false;
service.Credentials = new System.Net.NetworkCredential("XXXXX", "XXXX","XXXX");

You must enabled NTLM setting properties authentification if you are using PHP or Java Or XAMARIN Use NTLM Authentication

This piece of code below is working for me (I wasn't really adjusting the Service Tier - it has more or less the default settings):

service.ClientCredentials.Windows.ClientCredential.Domain = <domain>;
service.ClientCredentials.Windows.ClientCredential.UserName = <username>;
service.ClientCredentials.Windows.ClientCredential.Password = <password>;
service.ClientCredentials.Windows.AllowedImpersonationLevel = 
  System.Security.Principal.TokenImpersonationLevel.Delegation;

If that above doesn't work try to get rid of the domain from the NetworkCredential - just use your username and password (if the client and the server are in the same domain, obviously).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM