webservice check credential

casanovacasanova Member Posts: 194
edited 2013-01-30 in NAV Three Tier
hi all
how do I check credential in webservice to nav?
if user id is wrong then he/she cant login
i try this code but failed
try
                {
                    domain = textBoxDomain.Text;
                    uid = textBoxUserID.Text;
                    pwd = textBoxPassword.Text;
                    NetworkCredential credentials = new NetworkCredential(uid, pwd, domain);
                    SystemService systemService = new SystemService();
                    systemService.Credentials = credentials;
                    systemService.Url = baseURL + "SystemService";
                    systemService.PreAuthenticate = true;
                    MessageBox.Show("Welcome " + uid.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                } 

Comments

  • julkifli33julkifli33 Member Posts: 1,092
    hai anything about this?
    i need this too
    thanks
  • ara3nara3n Member Posts: 9,256
    what is the error?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • casanovacasanova Member Posts: 194
    there is no error
    but i cant authenticate
    because we cant check domain password from NAV or C#
  • yukonyukon Member Posts: 361
    Hi casanova,
    casanova wrote:
    there is no error
    but i cant authenticate
    because we cant check domain password from NAV or C#

    We no need to check domain password. We need to check login user is authenticate or not. And we can't check user id is wrong or password is incorrect. What we can do it, we can check login user is authenticate or not. Here is sample
            try
            {
                string _strUrl = "http://localhost:7047/DynamicsNAV/ws/SystemService";
                System.Net.WebRequest _webRequest = System.Net.WebRequest.Create(_strUrl);
                _webRequest.UseDefaultCredentials = false;
                _webRequest.Credentials = new System.Net.NetworkCredential("your-domain-login", "your-domain-password", "your-domain");
                System.Net.HttpWebResponse _httpWebResponse = (System.Net.HttpWebResponse)_webRequest.GetResponse();
            }
            catch (System.Net.WebException _webException)
            {
                string _Error = _webException.Message;
                if (_webException.Status == System.Net.WebExceptionStatus.ProtocolError)
                {
                    System.Net.HttpWebResponse _httpWebResponse = (System.Net.HttpWebResponse)_webException.Response;
                    if (_httpWebResponse != null)
                        Console.WriteLine("HTTP Status Code: " + (int)_httpWebResponse.StatusCode); //401 authentication fail,503 ServiceUnavailable
                    else
                    {
                        // no http status code available
                    }
                }
                else
                {
                    // no http status code available
                }
            }
    

    Best Regards,
    Yukon
    Make Simple & Easy
Sign In or Register to comment.