Connecting to Microsoft Dynamics CRM on-premise web service with Java?
Asked Answered
B

4

9

Are there any online resources which show the basic steps to access the Microsoft CRM on-premise web service with a client written in Java?

Which web service toolkit should I use?

I tried it with JAXB but there is a conflict in the WSDL element naming which requires a class customization. If I find the correct binding fix, I will post it here.

Burseraceous answered 12/7, 2009 at 11:30 Comment(5)
have you implemented Ms dynamics CRM, if so let you guide me to achieve the same. looking for you response.Workmanlike
@SenthilMg no we used a WCF client and a simple file based message interchange. See below for a hint that Axis 2 can be used.Burseraceous
i'm facing a problem Need help to fix the error, org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:296) at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:190) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommo‌​ns(CommonsHTTPTransportSender.java:364) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTra‌​nsportSender.java:208)..Workmanlike
@SenthilMg this should be a new question. It looks like the user credentials are wrong. Try to pass the same user name and passwort which you use in a browser to access the WSDL. The code shown in the answer below uses NTLM authentication, is this the same auth method in your environment?Burseraceous
below answer am getting error above at RetrieveMultipleResponseDocument rmrd = stub.RetrieveMultiple(rmd, catd, null, null); any help?Workmanlike
N
8

The Microsoft Dynamics CRM application on premise version uses Active Directory authentication. Although I never tried referencing the Microsoft Dynamics CRM web services from Java, I am sure it is feasible, as these are standard web services and therefor can be referenced from Java via SOAP, just like any other web service.

public class TestCRM {  

private static String endpointURL = "http://server:port/MSCrmServices/2007/CrmService.asmx";  
private static String userName = "username";  
private static String password = "password";  
private static String host = "server";  
private static int portport = port;  

//To make sure you are using the correct domain open ie and try to reach the service. The same domain you entered there is needed here  
private static String domain = "DOMAIN";   

private static String orgName = "THIS_IS_REQUIRED"; //this does the work....  


public static void main(String[] args) {  

    CrmServiceStub stub;  
    try {  
        stub = new CrmServiceStub(endpointURL);  
        setOptions(stub._getServiceClient().getOptions());  

        RetrieveMultipleDocument rmd = RetrieveMultipleDocument.Factory.newInstance();  
        RetrieveMultiple rm = RetrieveMultiple.Factory.newInstance();  

        QueryExpression query = QueryExpression.Factory.newInstance();  
        query.setColumnSet(AllColumns.Factory.newInstance());  
        query.setEntityName(EntityName.######.toString());  
        //query.setFilter...  

        rm.setQuery(query);  
        rmd.setRetrieveMultiple(rm);  

        //Now this is required. Without it all i got was 401s errors  
        CrmAuthenticationTokenDocument catd = CrmAuthenticationTokenDocument.Factory.newInstance();  
        CrmAuthenticationToken token = CrmAuthenticationToken.Factory.newInstance();  
        token.setAuthenticationType(0);     
        token.setOrganizationName(orgName);  
        catd.setCrmAuthenticationToken(token);  

        boolean fetchNext = true;  
        while(fetchNext){  
            RetrieveMultipleResponseDocument rmrd = stub.RetrieveMultiple(rmd,  catd, null, null);  
            RetrieveMultipleResponse rmr = rmrd.getRetrieveMultipleResponse();  
            BusinessEntityCollection bec = rmr.getRetrieveMultipleResult();  

            String pagingCookie = bec.getPagingCookie();  
            fetchNext = bec.getMoreRecords();  

            ArrayOfBusinessEntity aobe = bec.getBusinessEntities();  
            BusinessEntity[] myEntitiesAtLast = aobe.getBusinessEntityArray();  

            for(int i=0; i<myEntitiesAtLast.length; i++){  
                //cast to whatever you asked for...  
                ### myEntity = (###) myEntitiesAtLast[i];  
            }  
        }  
    }   
    catch (Exception e) {  
        e.printStackTrace();  
    }  
}  

private static void setOptions(Options options){  
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();  

    List authSchemes = new ArrayList();  
    authSchemes.add(HttpTransportProperties.Authenticator.NTLM);   
    auth.setAuthSchemes(authSchemes);   

    auth.setUsername(userName);  
    auth.setPassword(password);  
    auth.setHost(host);  
    auth.setPort(port);  
    auth.setDomain(domain);  
    auth.setPreemptiveAuthentication(false); //it doesnt matter...  
    options.setProperty(HTTPConstants.AUTHENTICATE, auth);  
    options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true"); //i think this is good.. not required though  
} 
Niel answered 12/7, 2009 at 11:34 Comment(5)
This source code looks good, almost exactly like the C# example code (which I used successfully). Do you know which SOAP toolkit has generated the service stub classes in Java?Burseraceous
@Joe, I tried out your snippet provided here but it results unsuccess, can you please provide your valuable suggestion to implement CRM.Showing error at RetrieveMultipleDocument rmd = RetrieveMultipleDocument.Factory.newInstance();Workmanlike
xception in thread "main" java.lang.ExceptionInInitializerError at com.microsoft.schemas.crm._2007.webservices.ExecuteDocument$Execute$Factory.newInstance(ExecuteDocument.java:70) at javaMSCRM.Login.main(Login.java:44) Caused by: java.lang.RuntimeException: Cannot load SchemaTypeSystem. Unable to load class with name schemaorg_apache_xmlbeans.system.s0C7B6541D611A1749D5105A4C55EC974.TypeSystemHolder.Workmanlike
@joe, Need help to fix the error, org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:296) at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:190) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:364) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:208)Workmanlike
@Niel - What would the code look like for connecting to crm 2011? Any idea?Protectionist
G
4

Java -> SOAP -> MS CRM 2011 Online : http://zsvoboda.blogspot.com/2011/03/connecting-to-microsoft-crm-2011-online.html

Gilolo answered 4/3, 2011 at 19:26 Comment(0)
S
1

The stub has been created with the Apache Axis2 framework.

Singlehandedly answered 28/7, 2010 at 9:57 Comment(0)
V
0

You can find resources here. You can even work with an example is available in Dynamics CRM SDK. As Manuel Freiholz said, you have to use Axis2.

https://msdn.microsoft.com/en-us/library/jj602979(v=crm.5).aspx

http://blogs.msdn.com/b/dynamics-coe/archive/2013/09/21/integrating-microsoft-dynamics-crm-2011-online-with-java-and-other-non-net-clients.aspx

Alternatively, you can use RESTFul web services through the OData interface offered by Dynamics (https://msdn.microsoft.com/en-us/library/gg334279.aspx)

Valedictory answered 9/3, 2015 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.