function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bryanobryano 

WSC - Setting session id and server URL after calling login()

Hello, after calling login() and try making a call, say query(), I get the following error:

 

exceptionMessage='Destination URL not reset. The URL returned from login must be set in the SforceService'

 

According to the SOAP API documentation for login() it says the following:

 

After logging in, a client application needs to perform these tasks:

  • Set the session ID in the SOAP header so that the API can validate subsequent requests for this session.
  • Specify the server URL as the target for subsequent service requests. You must change to the server URL, the login server only supports login calls.

How is this done when using the force.com WSC?  All the examples I've seen set the username and password in the ConnectorConfig.  I see there's a setSessionHeader() in PartnerConnection but I don't see any method to set the server url. 

 

Can someone point me in the right direction?

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

If you turn on manualLogin then its upto you to handle updating the stub after login, but you can just do

 

PartnerConnection conn = Connector.newConnection(username, password);

 

and it'll automatically do login and setup serverUrl/sessionId for you. (there's a version of newConnection that takes a ConnectorConfig if you have a non-default config you want to use)

All Answers

SuperfellSuperfell

WSC should do this for you, can you post a sample of your code that ends up with this error?

bryanobryano

Hi Simon,

 

My code looks something like this:

 

 

String url = "https://login.salesforce.com/services/Soap/u/29.0";

ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(url);
config.setServiceEndpoint(url);
config.setManualLogin(true);

PartnerConnection connection = new PartnerConnection(config);
LoginResult lr = connection.login(username, password);

 

 

 

SuperfellSuperfell

If you turn on manualLogin then its upto you to handle updating the stub after login, but you can just do

 

PartnerConnection conn = Connector.newConnection(username, password);

 

and it'll automatically do login and setup serverUrl/sessionId for you. (there's a version of newConnection that takes a ConnectorConfig if you have a non-default config you want to use)

This was selected as the best answer
SuperfellSuperfell

If for some reason you need to manually set the serverUrl, then i beleive its setServiceEndpoint() on the Config object.

bryanobryano

Thanks Simon for the info!