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
giri rockzzzzgiri rockzzzz 

Salesforce webservice consumption in Java issue

Hi Guys,

I have created a webservice in salesforce and generated WSDL file for it.And using some salesforce tools i have generated jar file and added it into my application .Now, i am facing login issue in it.

It says 

INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

i want to know how to saolve this issue .

Below is my code:

try {

ConnectorConfig c = new ConnectorConfig();

c.setUsername("giribhushan.svg@gmail.com");

c.setPassword("giribhushanguru123NCD8avhYG3G7Nunzy1fz0FsH");

 

SoapConnection sc = Connector.newConnection(c);

c.setSessionId(sc.getSessionHeader().getSessionId());

 

System.out.print("session id "+sc.getSessionHeader().getSessionId());

System.out.print("Institutes "+sc.getInstitutes());

} catch (ConnectionException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

 

Thank you

JitendraJitendra

Hi,

Find below Java code used to login using Partner WSDL. let me know if you need for the enterprise one:

public boolean login(String loginInstance, String profileName) {
		initiateValues(loginInstance, profileName);
		boolean success = false;
		startThread();
		try {
			ConnectorConfig config = new ConnectorConfig();
			System.out.println("\nLogin Using : " + sfdcUserName);
			config.setUsername(sfdcUserName);
			config.setPassword(sfdcPassword);
			config.setAuthEndpoint(sfdcAuthEndPoint);
			// config.setTraceFile("src/"+sfdcUserName+".txt");

			if (isProxy.trim().equals("1")) {
				System.out.println("Proxy Enabled for the Organization");
				config.setProxy(proxyHost, Integer.parseInt(proxyPort));
				config.setProxyUsername(proxyUserName);
				config.setProxyPassword(proxyPassword);
			} else {
				System.out.println("Proxy Not enabled for you");
			}

			// config.setTraceMessage(true);
			// config.setPrettyPrintXml(true);
			partnerConnection = new PartnerConnection(config);
			success = true;
			stopThread();
		} catch (ConnectionException ce) {
			ce.printStackTrace();
		} catch (Exception fnfe) {
			fnfe.printStackTrace();
		}
		stopThread();
		return success;
	}