Thursday, September 24, 2009

connecting Microsoft Dynamic CRM 3.0 with java code

hi All, I would like to share my experience to connecting ms crm with java code...

Its not difficult to connect ms crm 3.0 with java code using both ntlm and basic authentication..

First Step: download web service description files(CrmService.asmx, MetadataService.asmx) from Mircosoft Dynamics CRM

And convert to equivalent java classes

create a folder CrmService and execute this command

java -classpath C:\java\axis-1_4\lib\axis.jar;C:\java\axis-1_4\lib\activation.jar;C:\java\axis-1_4\lib\mail.jar;C:\java\axis-1_4\lib\axis-ant.jar;C:\java\axis-1_4\lib\commons-discovery-0.2.jar;C:\java\axis-1_4\lib\commons-logging-1.0.4.jar;C:\java\axis-1_4\lib\jaxrpc.jar;C:\java\axis-1_4\lib\log4j-1.2.8.jar;C:\java\axis-1_4\lib\saaj.jar;C:\java\axis-1_4\lib\wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java -v -a -O -1 CrmService.wsdl -o ./CrmService

do the same for metadataservice to convert to java code.

combine both sources..

Create new project in your eclipse, and test login..

For basic authentication , we can use axis1.4 file

To connect with ntlm authentication, we have to edit the client-config.wsdd file in axis1.4 jar, Hope that you all know about this.. please comment if you need further help with this..

/*added on +20101220 */
easy way to edit is: open the axis.jar file with winrar application
go to the folder org->apache->axis->client and open the file client-config.wsdd and edit the following changes and save. check once again the changes are there.


The following is the sample client-config.wsdd

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
<parameter name="disablePrettyXML" value="true">
<transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender">
<transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender">
<transport name="java" pivot="">

Along with axis jar, we need these two(commons-httpclient-3.1.jar, commons-codec-1.3.jar) jar files in our class-path to get ntlm authentication

sample code to login
CrmServiceSoapStub stub =  (CrmServiceSoapStub)
new CrmServiceLocator().getCrmServiceSoap(
new URL("http://###.###.#.###/MSCRMServices/2006/CrmService.asmx"));

WhoAmIRequest request=new WhoAmIRequest();
WhoAmIResponse response=(WhoAmIResponse)stub.execute(Request);

//can write on next post about connecting mscrm 4.0 with java code


  1. Hi, I'm trying run the command to convert the WSDL to Java but keep getting the following error:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/

    I've ensured that my PATH variable in Windows points to the lib directory in the Axis folder. The exact command I'm running is:
    C:\CrmService>java -classpath axis.jar;activation.jar;mail.jar;axis-ant.jar;comm
    jar;wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java -v -a -O -1 CrmDiscoveryServ
    ice.wsdl -o ./CrmDiscoveryService

    Any ideas?

  2. hi, sorry for late reply
    //Now I enabled the comment notification.

    in your command , the classpath is not correct, see my above command , give full path to the jar file like my above command or give relative path

  3. Hi Dave,
    have any experience about connecting CRM 4.0 Webservice with java?

  4. Hi Matthias,
    Yes. Do you have any issues ?

  5. hi Dave,

    i have issues conecting mscrm 4.0 using webservice with java.

    please can you help me to figureout the problem ?


  6. Dave,

    i have generated the stub classes and tried to use the sample you provided.
    the classes generated are different from the sample code.
    even though i tried to connect. but couldn't.

    please provide any sample snippet.


  7. please verify the WSDL2Java command again and compare with the above

  8. Hello David, I am getting error while creating a java class from Axis2 framework : The error code is -- "An error occurred while completeing process -java.lan.InterruptedExcpetion: org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: Can't serialize the policy.."

    Can you help me,. I am accessing CRM2011 IFD site and having 1.7 jre with axis2 and http compenent client.