0 votes
1 view
in Salesforce by (11.9k points)

I'm trying to establish a Connection to my Apex-Webservice but it fails every time. My Website is quite Simple:

global class AtlassianService 

{

    webService static String hello(String Name) 

    {

        return 'Hello '+Name+' ! :D';

    }

}

To generate the Client i just the way, which is described here:

java –classpath pathToJAR/wsc-22.jar com.sforce.ws.tools.wsdlc pathToWsdl/WsdlFilename​ pathToOutputJar/OutputJarFilename

Accessing the Webservice:

SoapConnection soap = Connector.newConnection("[email protected]", "XXXX");

System.out.println(soap.hello("WORLD")); // Invalid Session ( => SessionID is null)

If I use the PartnerConnection to get a valid SessionID everything works fine:

ConnectorConfig config = new ConnectorConfig();

config.setUsername(username);

config.setPassword(password);

config.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/24.0");

new PartnerConnection(config);

SoapConnection soap = Connector.newConnection(null, null);

soap.setSessionHeader(config.getSessionId());

System.out.println(soap.hello("WORLD"));

Does anybody have an idea why the first example fails?

1 Answer

0 votes
by (31.6k points)

All operations call of the wsc throws a ConnectionException or one of its particular subtypes in case of an error. So you must get an error message that would presumably help to solve the problem. In order to debug the SOAP messages sent and received by the wsc attach the following lines after the initialization of your ConnectorConfig:

conf.setPrettyPrintXml(true);

conf.setTraceMessage(true);

This will pretty-print the entire XML exchanged between your client and the web service. The response will also probably help you to find the reason for your problem.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...