1

Below is the complete code I have written to work with login() for Salesforce authentication. But, I am getting error if I execute the code in .Net client (Console Application). Can anybody please suggest me how to solve this problem.

My onsite coordinator has confirmed that everything is fine as long as Salesforce concerned.

Code

        private bool login()
    {
        string username = "kak.mca@gmail.com";
        string password = "Temp0r@ry";
        string securityToken = "";
        string resultSessionId = string.Empty;
        string resultServerUrl = string.Empty;
        binding = new SforceService();
        binding.Timeout = 60000;
        LoginResult lr;
        try
        {
            #region Method1
            //lr = binding.login(username, password);
            #endregion Method1
            #region Method2
            using(binding)
            {
                lr = binding.login(username, password);
                resultSessionId = lr.sessionId;
                resultServerUrl = lr.serverUrl;
            }
            #endregion Method2
            return true;
        }
        catch (SoapException e)
        {
            Console.WriteLine("Fault code: " + e.Code + Environment.NewLine + "Error message: " + e.Message + Environment.NewLine + "Stack trace:" + e.StackTrace);
            return false;
        }
    }

Error:

<font color='red'>Fault code: INVALID_LOGIN<br />
Error message: INVALID_LOGIN: Invalid username, password, security token; or user Locked out.<br />
Stack trace: at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
 at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
 at Walkthrough.sforce.SforceService.login(String username, String password) in <filepath>\Web Reference\sforce\Reference.cs:line 545
 at Walkthrough.QuickStartApiSample.login() in <filepath>\QuickstartApiSample.cs:line 54
</font>
Ashok kumar
  • 1,593
  • 4
  • 33
  • 68

2 Answers2

1

You are missing security token. You can get one by navigating to your name > Setup > Personal Setup > My Personal Information > Reset My Security Token. Your password variable should be

password = loginPassword + securityToken;

Or you can try Set Up Authorization, Authenticating Apps with OAuth and Digging Deeper into OAuth 2.0 on Force.com

Andrii Muzychuk
  • 1,151
  • 3
  • 20
  • 28
  • Hi Chiz, Thank you for your reply. I have tried the approach you have suggested, but with NO success. As I have seen in some other article, I have done the code without using security token also. Of-course, I have verified my Visual Studio solution once again with your suggestion. But, still the same error. – Ashok kumar Apr 01 '16 at 10:29
  • @Ashokkumar, I've checked other articles regarding C# and login to SF - your code is ok, if your password is password+securityToke. I suggest you check SF side. The URL (sandbox/production), to which you try to login. – Andrii Muzychuk Apr 01 '16 at 11:36
0

The error was due to improper credentials. When submitted proper credentials, everything went fine.

Ashok kumar
  • 1,593
  • 4
  • 33
  • 68