web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Unauthorized error 401 in dynamics nav web service client

(0) ShareShare
ReportReport
Posted on by

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

The request failed with HTTP status 401: Unauthorized.

my code in C# is the following :

 

public static List<Customer_Card.Customer_Card> GetCustomersList()

{

Customer_Card.Customer_Card[] Customers = new Customer_Card.Customer_Card[]{};

try

{

Customer_Card_Service service = new Customer_Card_Service();

service.UseDefaultCredentials = true;

service.Credentials = new NetworkCredential("xxxx", "xxxx","xxxx");

service.PreAuthenticate = true;

Customer_Card.Customer_Card cust = new Customer_Card.Customer_Card();

Customer_Card_Filter CustomerFilter = new Customer_Card_Filter();

Customers = service.ReadMultiple(new Customer_Card_Filter[] { }, "", 1000);

}

catch (Exception e)

{

Msg(e.Message.ToString());

}

return Customers.ToList();

}


any help will be appreciated

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Make sure the user that is used to running the NAV service has permission to access the dataase.

  • Community Member Profile Picture
    on at

    the user is assigned with the  permission : super

  • Verified answer
    keoma Profile Picture
    32,729 on at

    do not use both lines

    service.UseDefaultCredentials = true;

    service.Credentials = new NetworkCredential("user", "password","domain");

    either use UseDefaultCredentials OR set a specific credential.

    check, if the credential data are correct and the current windows/AD user or the user defined in the networkcredential constructor has the needed rights for connecting nav (and the sql database behind).

    check firewall and antivirus settings. take them offline, try again.

    also check error and warning entries in windows eventlog according web service calls.

  • Suggested answer
    Community Member Profile Picture
    on at

    Check following link. It might help.

    blogs.msdn.com/.../connecting-to-nav-web-services-from-c-using-web-reference.aspx

    Try to check the solution from NAV application server directly with Admin user and see the results.

  • Suggested answer
    Alexander Ermakov Profile Picture
    28,096 on at

    Usually this error comes when user is not authorized to access the server. What authentication type do you use?

  • Community Member Profile Picture
    on at

    what do you mean by authentication type?

    The user is assigned with a windows authentication user name in dynamic nav.

  • Community Member Profile Picture
    on at

    tried it didn't work.

  • Gaspode Profile Picture
    on at

    Hi there, did you ever get a solution to this? I'm having a similar problem in NAV 2016 where I cannot access the Web service unless the Use NTLM is ticked. If I try using the service without NTLM ticked, I always get a 401.

  • Srini Profile Picture
    100 on at

    HI, thanks for the point,  Not able to get the positive result on Test Web Connection if we use the Network service into NAV service. Once the logon crediential is changed, the test web connection is complete successful. Thanks for the point posted.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans