+ Start a Discussion
umesh pandeyumesh pandey 

Exception in thread "main" java.lang.ClassCastException: com.sforce.soap.enterprise.LoginResult cannot be cast to com.sforce.ws.bind.XMLizable


Step 1: Create enterprise.jar using enterprise wsdl

java -Dpackage -classpath force-wsc-32.0.0.jar;tools.jar;antlr-runtime-3.5.jar;ST4-4.0.7.jar com.sforce.ws.tools.wsdlc enterprise.wsdl enterprise.jar

Step 2: Added enterprise.jar and force-wsc-32.0.0.jar to java project class path.
Step 3: Create stub using enterprise.wsdl (com.sforce.soap.enterprise , com.sforce.soap.enterprise.fault , com.sforce.soap.enterprise.sobject )

Step 4: Created package wsc and a class


package wsc;

import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.GetUserInfoResult;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;

public class Main1 {
static final String USERNAME = "ux.p@gmail.com";
static final String PASSWORD = "Password with security token";
static EnterpriseConnection connection;

public static void main(String[] args) {

  ConnectorConfig config = new ConnectorConfig();
  config.setUsername(USERNAME);
  config.setPassword(PASSWORD);
  config.setTraceMessage(true);

  try {
   connection = Connector.newConnection(config);

   // display some current settings
   System.out.println("Auth EndPoint: "+config.getAuthEndpoint());
   System.out.println("Service EndPoint: "+config.getServiceEndpoint());
   System.out.println("Username: "+config.getUsername());
   System.out.println("SessionId: "+config.getSessionId());
  }
  catch (ConnectionException e1) { e1.printStackTrace();
  }
}

}


Step 5: When running this simple class getting below error

Exception in thread "main" java.lang.ClassCastException: com.sforce.soap.enterprise.LoginResult cannot be cast to com.sforce.ws.bind.XMLizable
at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:650)
at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:527)
at com.sforce.soap.enterprise.LoginResponse_element.loadFields(LoginResponse_element.java:62)
at com.sforce.soap.enterprise.LoginResponse_element.load(LoginResponse_element.java:54)
at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:651)
at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:527)
at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:174)
at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:148)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:99)
at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:568)
at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:364)
at com.sforce.soap.enterprise.Connector.newConnection(Connector.java:27)
at wsc.Main1.main(Main1.java:22)


Appreciate if anyone let me know what changes do i need to make it running.

kanhu daskanhu das
When we try to use both WSC and Apache Axis WSDL2Java stuff together in the same JVM or Project we get the ClassCastException.
Remove all the classes generated by Axis and use only the jar generatd from

java -classpath tools.jar;force-wsc-36.1.1.jar;rhino-1.7.7.jar;ST-4.0.8.jar com.sforce.ws.tools.wsdlc enterprise.wsdl wsdlGenFiles.jar

Try using rhino jar for generating the jar