|
GettingStarted
Force.com Web Service Connector (WSC)The Force.com Web Service Connector (WSC) is a high performing web service client stack implemented using a streaming parser. WSC also makes it much easier to use the Force.com API (Web Services/SOAP or Asynchronous/REST API). WSC can be used to invoke any doc literal wrapped web service. Downloading WSCYou can download a pre-built WSC jar file from: http://code.google.com/p/sfdc-wsc/downloads/list The pre-built jar files were generated using JDK 1.6 and only run on JDK 1.6. To build a jar file that can run on JDK 1.5, see "Building WSC from Source Code." Building WSC from Source CodePrerequisite: You need JDK 1.6 to compile WSC jar files. To compile jar files: 1. Download the source code from: http://code.google.com/p/sfdc-wsc/source/checkout 2. cd to dist directory. 3. run "ant all" to generate the wsc.jar file. Note: This ant target compiles the jar file to run on JDK 1.6. To compile the jar file so that it can run on JDK 1.5, run "ant –DcompileTarget=1.5 all" instead of "ant all". You still need to compile with JDK 1.6. Generating Stub Code from a WSDLRun wsdlc on the WSDL you have downloaded: java -classpath wsc.jar com.sforce.ws.tools.wsdlc *wsdl* *jar.file*
Write application codeWrite your client application. For example, the following code creates a new Account using partner API:
import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.*;
import com.sforce.ws.*;
public static void main(String args) {
ConnectorConfig config = new ConnectorConfig();
config.setUsername("username");
config.setPassword("password");
PartnerConnection connection = Connector.newConnection(config);
SObject account = new SObject();
account.setType("Account");
account.setField("Name", "My Account");
connection.create(new SObject[]{account});
}
Add wsc.jar and jar.file (generated by wsdlc) to your classpath, then compile and run your client application. |
Hi. I downloaded the pre-built WSC jar file and tried to run the sample code on Google App Engine. I get the following error: java.lang.UnsupportedOperationException?: Method not implemented
It happens at this call: EnterpriseConnection? connection = Connector.newConnection(userName, password);
Is this supposed to happen?
I'm using wsc-16_0.jar on Windows XP.
On Google app engine, you should use wsc-gae-16_0.jar.
Hi will wsc-16_0.jar file work on any WSDL SOAP services?
Hi. I downloaded wsc-gae-16_0.jar file and try to run wsdlc command on my enterprise wsdl. At command line : java com.sforce.ws.tools.wsdlc enterprise.wsdl enterprise.jar but the result is :
Exception in thread "main" java.lang.NullPointerException?
what's wrong? thankI am getting the same error as above. Any clues?
Thanks
If you get NullPointerException? then add tempdir path on the end of command. java -classpath wsc.jar com.sforce.ws.tools.wsdlc wsdl jar.file tempdir
I'm getting other error:
WSC?[wsdlc.run:290]Created temp dir: c:\temp\wsdl\gen WSC?[wsdlc.<init>:78]Generating Java files from schema ... Exception in thread "main" java.io.FileNotFoundException?: c:\temp\wsdl\gen\servi ces-repository-jbee-skg-com:RepositoryService?_v1r0\mypackage\GetDocumentResult?.j ava (Invalid directory name - contains ':' )
This happen because I have targetnamespace set on 'urn:services-repository-jbee-skg-com:RepositoryService?_v1r0'. What can I do with this ?
HI ,
I have a webservice created in .NET and I want to convert the wsdl of this webservice into jar file.I have tried with the tools provided with appengine but its giving errors.How to convert the WSDL into jar?does appengine have generic converter?or is it specific only to salesforce.com wsdl?
If you're getting the following stacktrace:
Exception in thread "main" java.lang.NullPointerException at com.sforce.ws.tools.wsdlc.checkTargetFile(wsdlc.java:115) at com.sforce.ws.tools.wsdlc.<init>(wsdlc.java:66) at com.sforce.ws.tools.wsdlc.run(wsdlc.java:288) at com.sforce.ws.tools.wsdlc.main(wsdlc.java:279)You may need to supply the full of path to the JAR file you wish to create, e.g.:
Hello Chaps
I am getting a different error now:
Exception in thread "main" com.sforce.ws.wsdl.WsdlParseException?: Unknown element: import
Hi,
I am trying to use this connector together with a salesforce.com Sandbox account. But I keep getting wrong user errors. Can you tell me where I have to change the server to the sandbox server (test.salesforce.com)?
Thanks in advance!
If you are having problems with your password, can you try appending your security token at the end of your password in the program?
Looking for the wsc-18.0.jar as specified in Force.com Bulk API Guide (http://www.salesforce.com/us/developer/docs/api_asynch/Content/asynch_api_code_set_up_client.htm). Any idea where I can find it? Thanks!
Exception in thread "main" com.sforce.ws.wsdl.WsdlParseException?: Unsupported Schema element found http://www.w3.org/2001/XMLSchema:attributeGroup. At: 255:42
Works fine for WSDL PARTNER but gives errors for WSDL METADATA, any solution ?
Hello,
I am getting the same error as "contactkannan"
" Exception in thread "main" com.sforce.ws.wsdl.WsdlParseException?: Unknown elemen t: import
"Anyone knows why this is happening?
Note that the WSDL that i am trying to work with is not a sf one!
Cheers!
Hello everyone I am getting this error can any one help me
C:\utsav\googleProject>java -classpath wsc-18.jar com.sforce.ws.tools.wsdlc MyWS DL.wsdl c:\utsav\googleproject\Myjar.jar WSC?[wsdlc.run:311]Created temp dir: C:\Users\Utsav\AppData?\Local\Temp\wsdlc-te mp-2282562548841630409-dir Exception in thread "main" com.sforce.ws.wsdl.WsdlParseException?: Parse error: F ound invalid XML. only whitespace content allowed before start tag and not - (po sition: START_DOCUMENT seen ...yright 1999-2010 salesforce.com, inc.\r\nAll Righ ts Reserved\r\n-->\r\n-... @9:2)
Caused by: com.sforce.ws.ConnectionException?: Found invalid XML. only whitespace ight 1999-2010 salesforce.com, inc.\r\nAll Rights Reserved\r\n-->\r\n-... @9:2)Caused by: com.sforce.ws.parser.XmlPullParserException?: only whitespace content allowed before start tag and not - (position: START_DOCUMENT seen ...yright 1999 -2010 salesforce.com, inc.\r\nAll Rights Reserved\r\n-->\r\n-... @9:2)
Could you change the sample code to have String as argument type for main method rather than a plain String? No big deal, I just downloaded WSC and tried to get it up and running with my Eclipse IDE. But then I ran into this weird issue with IDE complaining about missing main method. It took me a few minutes to figure out the problem with argument type. Silly of me, but I thought I would point it out anyways so others don't run into the same issue.
I am getting significant compilation errors when I try to generate the stub jar file. Is it having an issue because there is a package name of "10"? Is there a workaround?
java -classpath wsc-19.jar com.sforce.ws.tools.wsdlc OCRWebService.WSDL.xml OCRWebService.jar WSC?[wsdlc.run:312]Created temp dir: /var/folders/+Q/+QusXyZNHjqOyTZGQYMa-k+++TI/-Tmp-/wsdlc-temp-31264270122093175-dir WSC?[wsdlc.<init>:79]Generating Java files from schema ... WSC?[wsdlc.<init>:79]Generated 16 java files. WSC?[wsdlc.compileTypes:262]Compiling to target 1.6... /var/folders/+Q/+QusXyZNHjqOyTZGQYMa-k+++TI/-Tmp-/wsdlc-temp-31264270122093175-dir/com/sforce/soap/10/OCRWebServiceRecognize_element.java:1: ';' expected package com.sforce.soap.10;
/var/folders/+Q/+QusXyZNHjqOyTZGQYMa-k+++TI/-Tmp-/wsdlc-temp-31264270122093175-dir/com/sforce/soap/10/OCRWebServiceRecognize_element.java:68: <identifier> expected/var/folders/+Q/+QusXyZNHjqOyTZGQYMa-k+++TI/-Tmp-/wsdlc-temp-7747198376826189011-dir/com/sforce/soap/10/jj/OCRWSSettings.java:310: ';' expected 100 errors Error: Failed to compile
thanks!
The source code of com.sforce.soap.partner.wsc.Connector is as follows.
package com.sforce.soap.partner.wsc; import com.sforce.ws.ConnectorConfig; import com.sforce.ws.ConnectionException; /** * Generated class, please do not edit. */ public class Connector { public static final String END_POINT = "https://www.salesforce.com/services/Soap/u/18.0"; public static PartnerConnection newConnection(String username, String password) throws ConnectionException { ConnectorConfig config = new ConnectorConfig(); config.setUsername(username); config.setPassword(password); return newConnection(config); } public static PartnerConnection newConnection(ConnectorConfig config) throws ConnectionException { if (config.getAuthEndpoint() == null) { config.setAuthEndpoint(END_POINT); } if (config.getServiceEndpoint() == null) { config.setServiceEndpoint(END_POINT); } return new PartnerConnection(config); } }Obviously, the endpoint URL is hardcoded. So I guess we need to explicitly set the endpoint to Sandbox if we want to connect it
ConnectorConfig config = new ConnectorConfig(); config.setUsername("username"); config.setPassword("password"); // explicitly set the endpoint config.setAuthEndpoint("https://test.salesforce.com/services/Soap/u/18.0");Yes, setting the endpoint this way makes the code re-usable.
I am invoking an SAP ABAP based web service from GAE using WSDL data connection. I am unable to authenticate. I got "Logon Error Message". It works(authenticate) fine running as Java application or running on GAE calling web services with no authentication. Please let me know how to do this. Thanks a lot
Can someone Please let me know how to set DateTime? for WSC? I tried with many formats but I did not get the correct date and time in to salesforce. It shows one day less and wrong time.
Here is my code
package com.date.test; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.*; import java.util.TimeZone; //import com.sforce.async.SObject; import com.sforce.soap.partner.Connector; import com.sforce.soap.partner.PartnerConnection; import com.sforce.soap.partner.SaveResult; import com.sforce.soap.partner.sobject.SObject; import com.sforce.ws.ConnectorConfig; import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException; public class TimeZoneConvertorTest { public static Date getDateInTimeZone(Date currentDate, String timeZoneId) { TimeZone tz = TimeZone.getTimeZone(timeZoneId); Calendar mbCal = new GregorianCalendar(TimeZone.getTimeZone(timeZoneId)); mbCal.setTimeInMillis(currentDate.getTime()); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, mbCal.get(Calendar.YEAR)); cal.set(Calendar.MONTH, mbCal.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, mbCal.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, mbCal.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, mbCal.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, mbCal.get(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, mbCal.get(Calendar.MILLISECOND)); return cal.getTime(); } private void convertTimeZone() throws Exception { Date d1 = null; Date d2 = null; String date = "11/28/2006 09:45:12"; String formattedDate = null; System.out.println("Actual Date String From Coldfusion : " + date); // Date format in MM/dd/yyyy hh:mm:ss DateFormat df1 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); // df1.setTimeZone(TimeZone.getTimeZone("EST")); // Date format in yyyy-MM-dd'T'hh:mm:ss'Z' DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); try { // Parses the value and assumes it represents a date and time in the EST timezone d1 = df1.parse(date); System.out.println("Original date After Converting to Date object " + d1); System.out.println("Date Object Converted to UTC " + getDateInTimeZone(d1, "UTC")); d1 = getDateInTimeZone(d1, "UTC"); // Format the date to yyyy-MM-dd'T'hh:mm:ss'Z' formattedDate = df2.format(d1); System.out.println("After changing the format to UTC " + formattedDate); df2.setTimeZone(TimeZone.getTimeZone("UTC")); // Parse it to date type d2 = df2.parse(formattedDate); System.out.println("Date after parsing : " + d2); } catch (ParseException pe) { pe.printStackTrace(); } ConnectorConfig config = new ConnectorConfig(); config .setServiceEndpoint("https://login.salesforce.com/services/Soap/u/17.0"); config .setAuthEndpoint("https://login.salesforce.com/services/Soap/u/17.0"); config.setUsername("my username"); config.setPassword("xyz"); PartnerConnection connection = null; try { connection = Connector.newConnection(config); SObject account = new SObject(); account.setType("Account"); account.setField("Name", "Account 1"); account.setField("Customer_Signed_Date__c", getDateInTimeZone(d1, "UTC")); SaveResult[] results = connection .create(new SObject[] { account }); System.out.println(">>>>>>Created Account : " + results[0].getId()); } catch (Exception e) { e.printStackTrace(); } } }What is the user name and password to use when using wsc_22.jar? I'm getting the following message:
failed [LoginFault [ApiFault exceptionCode='INVALID_LOGIN'
] ]Thanks,
Wen
Hi,
the exemple has to be updated for the last version right ?
I dont find PartnerConnection? / SObject classes
has someone a working example ?
I am completely lost.
I have a working sf application, NOT using the WSC lib.. and using the enterprise wsdl, from java (built with wsdl2java), developed and debugged with eclipse.. been fine for a year.
now I want to move to the partner wsdl, and the wsc libs look to provide so easier function.. cool.. should be an easy conversion
download the wsc-22.jar today, download the partner wsdl from my org, use the wsc jar to generate the partner.jar from the partner wsdl.. no problem add the partner jar and the wsc jar to my eclipse project.. no problem
but 'SObject.setField(name, object)' is NOT in either jar file. I look at the generated partner jar SObject class, says it 'extends' XMLObject form wsc.jar.. ok but I don't see the inherited methods.
the examples say
import com.sforce.partner.sobject.wsc.SObject but I don't find that package and class. 'wsc.SObject'
all the examples on SF http://www.salesforce.com/us/developer/docs/api/index_Left.htm#CSHID=sforce_api_partner.htm|StartTopic=Content%2Fsforce_api_partner.htm|SkinName=webhelp use setField()..
so.. what did I miss?
found it.. cause I am building a plugin for our server, there was one more classpath to fix
After importing the output jar to my Java project I get error messages for every class and almost every method saying things like "com.sforce.ws cannot be resolved to a type" when I try to use the imported folders and files as source folders.
Also all code seems to be put on one row in each class.
Any thoughts on how and where to import and use the library?
Thanks / Nick
Solved this myself. Only lack of Eclipse knowledge. Look here if you also want to know -> http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)
can someone please let me How to get the date field from salesforce and display the correct date formate in PDF?
Hi can anybody tell me how to test webservice in salesforce.com