web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Consuming REST API's using JAVA fails

(0) ShareShare
ReportReport
Posted on by

Hello All,

I am new to ms dynamics. What i am trying to do is consume REST and SOAP API's using Java but fail to do so.

The error that i get for REST API's with this code https://code.msdn.microsoft.com/Consuming-CRM-REST-Service-ae24a15e#content  is , it does not generate the classes it is supposed to and gives the following error.

org.apache.olingo.odata2.api.ep.EntityProviderException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[81,5]
Message: The declaration for the entity "ContentType" must end with '>'.

Can we not consuming services if i am on a trial account. Or where am i going wrong. 

Thank you

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi

    For CRM 2011, it is not possible to call the oData endpoint from an external application.

    you need user SOAP end point,

    For example, refer to article below:

    msdn.microsoft.com/.../jj602979(v=crm.5).aspx

    Hope this help!

    If you're satisfied with my answer, please mark it as verified.

  • Community Member Profile Picture
    on at

    Hello thank you for your response.

    I have created a trial account for MSdynamics. When I generate the REST point from Developer Resources option it gives me link for 2011 i.e https://<server>.crm5.dynamics.com/XRMServices/2011/OrganizationData.svc/

    How can i change this.

    Next i have tried the article which you suggested.It generates all the files but again i am using 2011 SOAP API's. This fails as well and gives me an error :

    [ERROR] IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage

    Exception in thread "main" java2crmpack.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage: IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

    at java.lang.reflect.Constructor.newInstance(Unknown Source)

    at java.lang.Class.newInstance0(Unknown Source)

    at java.lang.Class.newInstance(Unknown Source)

    at java2crmpack.DiscoveryServiceStub.execute(DiscoveryServiceStub.java:225)

    at java2crmpack.Main.discoverOrganizationUrl(Main.java:454)

    at java2crmpack.Main.main(Main.java:112)

  • Suggested answer
    Community Member Profile Picture
    on at
  • Community Member Profile Picture
    on at

    Hi,

    i have tried the article which you suggested.It generates all the files but again i am using 2011 SOAP API's. This fails as well and gives me an error :

    [ERROR] IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage

    Exception in thread "main" java2crmpack.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage: IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

    at java.lang.reflect.Constructor.newInstance(Unknown Source)

    at java.lang.Class.newInstance0(Unknown Source)

    at java.lang.Class.newInstance(Unknown Source)

    at java2crmpack.DiscoveryServiceStub.execute(DiscoveryServiceStub.java:225)

    at java2crmpack.Main.discoverOrganizationUrl(Main.java:454)

    at java2crmpack.Main.main(Main.java:112)

  • Community Member Profile Picture
    on at

    Also when i try to consume this wsdl using SOAP UI i get the following error:

    Source: https://<server>.api.crm5.dynamics.com/XRMServices/2011/Organization.svc?singleWsdl Error: type 'ArrayOfEntityKeyMetadata@schemas.microsoft.com/.../Metadata&; not found.  Source: https://<server>.api.crm5.dynamics.com/XRMServices/2011/Organization.svc?singleWsdl Error: type 'DateTimeBehavior@schemas.microsoft.com/.../Metadata&; not found.  Source: https://<server>.api.crm5.dynamics.com/XRMServices/2011/Organization.svc?singleWsdl Error: type 'KeyAttributeCollection@schemas.microsoft.com/.../Contracts&; not found.  

    Is there any problem with my wsdl

  • Verified answer
    Community Member Profile Picture
    on at

    refer to this article please:

    jlattimer.blogspot.fr/.../soap-only-authentication-using-java.html

  • Community Member Profile Picture
    on at

    Thank you for the link. This lets me connect to CRM and displays my name as well... but no luck in creating and retrieving accounts.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    Try generate queries using SOAP Logger application, it allows you to write your queries in Visual Studio using QueryExpression and capture the format of the fetch.

    refer this:

    nishantrana.me/.../updated-soaplogger-for-crm-2013-to-generate-javascript

    www.powerobjects.com/.../microsoft-dynamics-crm-soap-logger-a-tool-that-can-greatly-simplify-writing-http-requests

    Hope this help!

  • Community Member Profile Picture
    on at

    Hi ,

    I tried this works well, generates the soap request and also works when i execute it using C#. When i try to execute the same using java gives me error status code 500. I am using the following code, SOAP is generated using C#. when i use the same url it authenticates me. only does not perform CRUD operations

    public static String Create(CrmAuthenticationHeader authHeader, String id, String url) throws IOException, SAXException,ParserConfigurationException
    {
    StringBuilder requestMain = new StringBuilder();

    requestMain.append("<s:Body>");
    requestMain.append("<Create xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">");
    requestMain.append("<entity xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">");
    requestMain.append("<a:Attributes xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">");
    requestMain.append("<a:KeyValuePairOfstringanyType>");
    requestMain.append("<a:Id>" + id + "</a:Id>");
    requestMain.append("<a:LogicalName>systemuser</a:LogicalName>");
    requestMain.append("<a:Name i:nil=\"true\" />");
    requestMain.append("<b:key>firstname</b:key>");
    requestMain.append("<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">Neha</b:value>");
    requestMain.append("</a:KeyValuePairOfstringanyType>");
    requestMain.append("<a:KeyValuePairOfstringanyType>");
    requestMain.append("<b:key>lastname</b:key>");
    requestMain.append("<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">Glynn</b:value>");
    requestMain.append("</a:KeyValuePairOfstringanyType>");
    requestMain.append("</a:Attributes>");
    requestMain.append("<a:EntityState i:nil=\"true\" />");
    requestMain.append("<a:FormattedValues xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />");
    requestMain.append("<a:Id>00000000-0000-0000-0000-000000000000</a:Id>");
    requestMain.append("<a:LogicalName>contact</a:LogicalName>");
    requestMain.append("<a:RelatedEntities xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />");
    requestMain.append("</entity>");
    requestMain.append("</Create>");
    requestMain.append("</s:Body>");

    Document xDoc = CrmExecuteSoap.ExecuteSoapRequest(authHeader,requestMain.toString(), url);

    System.out.println("xDoc"+xDoc);

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans