0

I'm trying to access MicroSoft Dynamic CRM 2011 online webservices from Java but no luck so far.

I got Organization WSDL file and generated required java stub files with the help of Axis2 (wsdl2Java).

And my simple client code is

public class TestCRM2 {

public static void main(String[] args) {

    try {   

        // create query
        QueryExpression query = new QueryExpression();
        query.setEntityName("Contact");

        ArrayOfstring colAra = new ArrayOfstring();
        colAra.addString("fullname");

        ColumnSet columnSet = new ColumnSet();
        columnSet.setAllColumns(false);
        columnSet.setColumns(colAra);

        PagingInfo pageinfo = new PagingInfo();
        pageinfo.setCount(10);
        pageinfo.setPageNumber(1);

        query.setColumnSet(columnSet);
        query.setPageInfo(pageinfo);            

        ConditionExpression condition = new ConditionExpression();
        condition.setAttributeName("fullname");
        condition.setOperator(ConditionOperator.Equal);

        ArrayOfanyType values = new ArrayOfanyType();
        values.setAnyType(new String[] {"something"});
        condition.setValues(values);

        RetrieveMultiple retrieveMultiple = new RetrieveMultiple();
        retrieveMultiple.setQuery(query);

        OrganizationServiceStub stub = new OrganizationServiceStub();           

        //set Timeout 
        ServiceClient serviceClient =  stub._getServiceClient();
        serviceClient.getOptions().setTimeOutInMilliSeconds( 3 * 60 * 1000);
        /*serviceClient.getOptions().setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION, HTTPConstants.HEADER_PROTOCOL_10);
        serviceClient.getOptions().setProperty(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED,false);*/         

        RetrieveMultipleResponse response = stub.retrieveMultiple(retrieveMultiple);            

        EntityCollection collection = response.getRetrieveMultipleResult();
        int count = collection.getTotalRecordCount();
        System.out.println(count);      

    } catch (Exception e) {
        e.printStackTrace();
    }
}}

When i run this from Eclipse, i get the following runtime error

org.apache.axis2.AxisFault: Connection reset
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.microsoft.schemas.xrm._2011.contracts.OrganizationServiceStub.retrieveMultiple(OrganizationServiceStub.java:1177) at test.TestCRM.main(TestCRM.java:105)
 Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:755)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
... 9 more

Is there any thing I'm missing in my client code. Your help is highly appreciated.

Regards,

Jason Lattimer
  • 2,858
  • 15
  • 14
Muni
  • 11
  • 2
  • Try this stack link: http://stackoverflow.com/questions/1115865/connecting-to-microsoft-dynamics-crm-web-service-with-java –  Jun 01 '12 at 03:34

1 Answers1

1
  1. You have to append "/web" at the end of your endpoint url in service client.
  2. You will have to provide NTLM2 authenticator implementation and register it with httpclient used by your stub.
Asif Khan
  • 11
  • 1
  • I've dealt with a few WCF services in the past but what is the /web extension? On a side note - the /web triggers the NTLM/Negotiate authentication mechanisms in the CRM Endpoint ... from there all I needed to do was configure my HttpClient for NTLM support. – Travis Sharp May 07 '13 at 21:51