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
AlexHt1AlexHt1 

Webservice from java newbie questions

Hello,

 

I am new to Webservices and soap. I have been trying to call a webservice from java but everything I try does not seem to work. This is the class I am trying to call from java.

 

global class DNAForceWS {
    webservice static Boolean test()
    {
        return true;
    }
}

 

1) When I want to update Objects such as the Account object, I create a WSDL for the enterprise API, then I use WSC for api to generate the class. But, it seems the the webservice class is not present at all in this WSDL. I need to click on the link next to the class to generate a WSDL specific for this class. Then I can use any of multiple tools to build the classes from it, AXIS1.4, AXIS2, JAX-WS, WSC. Is this correct? Can I use the WSC to generate the class?

AlexHt1AlexHt1

2) I have used the WSC connector to create two jar files. The first file was created by consuming the enterprise wsdl. The second jar file was created by consuming the webservice wsdl file. Upon inspecting the objects I get an entepriseconnection object and a soapconenction object. The EnterpriseConnection object is able to log into salesforce, update, insert, query and delete objects, but cannot call a webservice. However, the SoapConnection object does have a method to call the webservice. I cannot connect a soapconnection object. Here is the code I have:

 

import com.sforce.soap.enterprise.Connector; //From the enterprise wsdl
import com.sforce.soap.enterprise.EnterpriseConnection; //From the enterprise wsdl
import com.sforce.soap.WebServices.*; //From the webservice wsdl.

ConnectorConfig config = new ConnectorConfig(); config.setUsername(USERNAME); config.setPassword(PASSWORD); connection = Connector.newConnection(config);
SoapConnection soap = (SoapConnection)connection; //Error: SoapConnection cannot be casted from enterpriseconnection

 How can I initialize the SoapConnection so that it is ready for business?

AlexHt1AlexHt1

To initialize the SoapConnection, I have tried

 

ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
SoapConnection soap = new SoapConnection(config);

soap.test();

 However, I get this error:

 

com.sforce.ws.ConnectionException: Failed to send request to null
	at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:129)
	at com.sforce.soap.DNAForceWS.SoapConnection.test(SoapConnection.java:177)
	at com.dnaforce.salesforce.SalesforceConnect.ProcessOrder(SalesforceConnect.java:128)
	at com.dnaforce.ProcessTransaction.doPost(ProcessTransaction.java:41)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:680)
Caused by: java.net.MalformedURLException
	at java.net.URL.<init>(URL.java:601)
	at java.net.URL.<init>(URL.java:464)
	at java.net.URL.<init>(URL.java:413)
	at com.sforce.ws.transport.JdkHttpTransport.connectRaw(JdkHttpTransport.java:105)
	at com.sforce.ws.transport.JdkHttpTransport.connect(JdkHttpTransport.java:79)
	at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:107)
	... 17 more

 

AlexHt1AlexHt1

Well, that was more painfull than it should have been but I finaly got it working. In case anyone is interested and for future reference, this is the code that works.

ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
					
SoapConnection soap = com.sforce.soap.DNAForceWS.Connector.newConnection(config);
soap.setSessionHeader(connection.getSessionHeader().getSessionId());
soap.test();

 The key was to use the connector object present in the class definition of the webservice, not the connector produced by the enterprise wsdl. 

 

==Also it seems it will only work if I set the headers to a previously connection enterprisewsdl connection. So WTF...?