0

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 ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
carlkassar
  • 7
  • 1
  • 5

4 Answers4

1

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!

CGuy
  • 38
  • 4
0

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.

Rknabben
  • 29
  • 6
  • Question : is there a difference (in the client code ) between a client consuming a web service over http and a client consuming a web service over https ? – carlkassar Feb 19 '16 at 07:25
  • Not as far as I know, apart from the https:// in de server specification. Did you check if you have a default company set? We once went crazy looking for an 401 error, and found out that it was this field. (and be careful, some documentation is wrong on this subject. (Wrong key name). If you use the Microsoft Dynamics NAV Administration you should be alright. Btw: when using default credentials; what credentials are actually transferred? do these credentials have access? (if you are for instance creating a web application, isn't the serviceaccount of the webserver being used?) – Rknabben Feb 20 '16 at 08:41
0

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

ali bencharda
  • 51
  • 1
  • 6
0

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).

kubanek
  • 21
  • 2
  • 5