I have a user account on a clients Salesforce. These credentials are used on our Web service to connect and upload data to that clients Salesforce account.

However I have found that only my PC will allow the logging in to the API, this is not ideal as I need to have multiple users logged in using the same account and on different PC's in our organisation.

How can I fix this issue?

Here is the exception that is thrown:

------------- Top Exception -------------
------- Source -------

------- Message -------
Unable to connect to the remote server

------- Stack Trace -------
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebONE.SalesForceReference.SforceService.login(String username, String password)
at WebONE.GeneralUtilities.SalesForce.SalesForceHelper.Login()
at WebONE.Service.CampaignService.CreateNewSalesForceLead())

------- Message -------
No connection could be made because the target machine actively refused it

------- Stack Trace -------
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)

Here is a snippet of the Logs from SalesForce

Login Time (Australian Eastern Daylight Time)   Source IP   Login Type  Status  Browser Platform    Application Login URL
4/07/2013 12:19 Salesforce.com IP   Remote Access 2.0   Success Unknown Unknown Community   login.salesforce.com
4/07/2013 9:37 Application Success Chrome 27   Windows 7   Browser login.salesforce.com
3/07/2013 17:27 Application Success Chrome 27   Windows 7   Browser na5.salesforce.com
4/07/2013 12:40 Other Apex API  Success .NET Unknown    Unknown N/A 

I believe that the last record was created when I successfully ran the code locally

  • Have you checked the login history for the user after it fails? If you are hitting the right org, it will tell you the reason for the reject. If you see no entry then I'd check that the endpoint is set correctly to either login.salesforce.com or test.salesforce.com and the user name is correct. – Daniel Hoechst Jul 4 '13 at 1:34
  • how can I check the login history? – Matthew Pigram Jul 4 '13 at 2:04
  • You may need to get your client to check it for you depending on what permissions they have given you. Login to the web UI of Salesforce and go to Setup (May be under Your Name, depending on which version of setup is enabled.) > Manage Users > Users. Click on your user name and the login history is at the bottom. – Daniel Hoechst Jul 4 '13 at 2:13
  • that doesnt show any API access as far as I can tell, just typical login access through the browser. In the code I am using SforceService.login(username, password + securityToken) to gain access. Also I am an Admin user so I should have sufficient access right? – Matthew Pigram Jul 4 '13 at 2:18
  • ah just found the logs you are talking about, interestingly none are appearing when I try to run the code through production, however in as localhost they do appear in the logs. Any ideas why? – Matthew Pigram Jul 4 '13 at 2:26

The server (salesforce.com) wouldn't actively refuse a connection from legitimate locations, although they do have a blacklist of IPs they won't accept connections from (known spammers). A more likely scenario is the related to the network configuration of the other system. It may be either that a proxy is required, or the firewall on the computer or network needs to be configured correctly. Try using a different account to confirm that it is the application's access, not the user account, that is at fault. Depending on the specific scenario, you'll need to either configure the application to use a proxy, or you'll have to configure the firewall to allow access to that program.

  • as mentioned below, it appears to work when I run my code locally, however my machine and the production server run on the same network, so I'm uncertain why it is being refused – Matthew Pigram Jul 3 '13 at 23:32
  • I have updated the error message, it appears as though the problem is happening at the login call. – Matthew Pigram Jul 4 '13 at 0:03

Clients are not able to gain access because their IP addresses are not listed in "Network Access".

You can handle this in following ways:

1) List Client IPs to "Network Access" in Salesforce Setup.

2) While invoking the service,supply credential as "username" and "password+Security Token" instead of username and password alone.

  • I am already providing a security token, the odd thing is that it runs correctly locally, but when using our deployment environment it fails to login, perhaps I do need to add the IP's, should I set it to the publicly visible IP address of our production server? – Matthew Pigram Jul 3 '13 at 6:48
  • You need to add the public IP of the server which is hosting your web service application to Salesforce. – Vignex Jul 3 '13 at 7:29
  • tried this and it still failed... should I remove the security token and see if that fixes things? – Matthew Pigram Jul 3 '13 at 7:36
  • 1
    The security token is instead of whitelisting IP addresses. – Mike Chale Jul 3 '13 at 11:20
  • There can be User lockout also because of the previous failure attempts. – Vignex Jul 3 '13 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.