Export (0) Print
Expand All

Walkthrough: Connect Using Java for Microsoft Dynamics CRM Online

Dynamics CRM 2011
[Applies to: Microsoft Dynamics CRM 2011]

The Microsoft Dynamics CRM SDK contains sample code that demonstrates how to use Java to access Microsoft Dynamics CRM Online and perform Create, Read, Update, and Delete operations. This sample code uses Windows Communication Foundation (WCF) and the SOAP interface to access the operation data and metadata API published by Microsoft Dynamics CRM Online. The sample code can be found in the folder Walkthroughs\Java2CRM\Java2CRMCRUD.

This walkthrough uses Eclipse but the steps for using NetBeans are similar.

To run this sample code you must have the following items:

  1. Run Eclipse.

  2. Click File, click New, and then select Java Project.

  3. In the Project Name field, type Java2CRMCRUD and, in the Project Location field, type C:\Projects\Java2CRMCRUD.

  4. Click Finish.

  5. Create a folder at C:\Projects\Java2CRMCRUD.

  6. Navigate to the installation of the Axis2 1.6.1 package folder and copy the .jar files in the axis2-1.6.1\lib folder into the C:\Projects\Java2CRMCRUD\lib folder.

  7. Copy the addressing-1.6.1.mar file located in the axis2-1.6.1\repository\modules folder into the C:\Projects\Java2CRMCRUD\lib folder.

  8. Navigate to the installation of the Apache HTTP Components and copy the .jar files from the httpcomponents-client-4.1.3\lib folder into the C:\Projects\Java2CRMCRUD\lib folder.

  9. In Project Explorer, left-click the Java2CRMCRUD project, click Build Path, and then select Configure BuildPath.

  10. On the right pane make sure that the Libraries tab is selected.

  11. Click Add JARS and browse to a location where you copied all the libraries, C:\Projects\Java2CRMCRUD\lib.

  12. Select all files from the lib folder and click Open.

  13. Click OK to add the referenced libraries.

  14. In Project Explorer, verify that all the libraries are showing up under the Referenced Libraries tree node under the Java2CRMCRUD project.

  1. Make sure that the JAVA_HOME environment variable is set to the correct JDK path, for example, JAVA_HOME=C:\Program Files\Java\jdk1.6.0_29\jre

  2. At the command prompt, navigate to the installed axis2-1.6.1\bin folder, and type:

    WSDL2Java -uri https://disco.crm.dynamics.com/XRMServices/2011/Discovery.svc?wsdl -p java2crmpack -s -o c:\projects\Java2CRMCRUD

    noteNote
    If the Microsoft Dynamics CRM Online instance you are connecting to is in EMEA or APAC, the URL you use to access the discovery service is https://disco.crm4.dynamics.com or https://disco.crm5.dynamics.com.

    If you don't know the URL for the services, do the following:

    1. Launch Internet Explorer and sign in to Microsoft Dynamics CRM Online.

    2. Navigate to Settings > Customizations.

    3. Click Developer Resources.

    4. Copy the URL for the Discovery Service and append “?wsdl” to it.

    You can learn about the options used on the WSDL2Java command by typing help after the command.

  3. At the command prompt, navigate to the installed axis2-1.6.1\bin folder, and type:

    WSDL2Java -uri https://yourcrmonlineinstance.crm.dynamics.com/XRMServices/2011/Organization.svc?wsdl -p java2crmpack -s -o c:\projects\Java2CRMCRUD, where yourcrmonlineinstance is replaced with the appropriate Microsoft Dynamics CRM Online organization unique name.

    noteNote
    If the Microsoft Dynamics CRM Online instance you are connecting to is in EMEA or APAC, the URL you use to access it will be https://yourcrmonlineinstance.crm4.dynamics.com or https://yourcrmonlineinstance.crm5.dynamics.com.

  4. After the command window has generated the classes, close it. Verify the command’s output at c:\projects\Java2CRMCRUD\src\java2crmpack. This folder should show the following files:

    • DiscoveryServiceStub.java

    • IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage.java

    • IOrganizationService_Associate_OrganizationServiceFaultFault_FaultMessage.java

    • IOrganizationService_Create_OrganizationServiceFaultFault_FaultMessage.java

    • IOrganizationService_Delete_OrganizationServiceFaultFault_FaultMessage.java

    • IOrganizationService_Disassociate_OrganizationServiceFaultFault_FaultMessage.java

    • IOrganizationService_Execute_OrganizationServiceFaultFault_FaultMessage.java

    • IOrganizationService_Retrieve_OrganizationServiceFaultFault_FaultMessage.java

    • IOrganizationService_RetrieveMultiple_OrganizationServiceFaultFault_FaultMessage.java

    • IOrganizationService_Update_OrganizationServiceFaultFault_FaultMessage.java

    • OrganizationServiceStub.java

    ImportantImportant
    Do not try to open the OrganizationServiceStub.java file in Eclipse or the NetBeans IDE because it is quite large and the IDE will stop functioning.

  1. In Project Explorer, left-click the Java2CRMCRUD project and select Refresh, or press F5, to see the newly generated proxy classes show up in the source folder.

  2. Navigate to the SDK Java sample code folder at SDK\Walkthroughs\Java2CRM\Java2CRMCRUD\src\java2crmpack and copy all .java files to the C:\Projects\Java2CRMCRUD\src\java2crmpack folder. This copies the files required for the Microsoft account token exchange and methods necessary to authenticate and invoke Create, Read, Update, and Delete operations with Microsoft Dynamics CRM Online.

  3. Navigate to the SDK Java sample code folder at SDK\Walkthroughs\Java2CRM\Java2CRMCRUD\src and copy the axis2.xml and log4j.properties files to C:\Projects\Java2CRMCRUD\src folder. ApacheAXIS2 needs these files for logging purposes

  4. In Project Explorer, left-click the Java2CRMCRUD project and select Refresh, or press F5, to see the newly added axis2.xml and log4j.properties files show up in the source folder.

  1. Open the Main.java file in the IDE, replace myliveid@outlook.com, mypassword and mycrmonlineinstance with the appropriate credentials and the Microsoft Dynamics CRM Online organization unique name.

  2. Run the application by selecting Run from the menu.

    You should see the following results in the Console window:

    Java console output

If you experience errors when you run the samples, check the following:

  • You have followed all instructions in this document correctly.

  • The server, organization, and logon credentials you entered are correct.

  • Your account on the Microsoft Dynamics CRM Online server has the required permissions to perform the sample’s intended operation.

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft