问题
I am trying to connect to MS Dynamics CRM 2011 from Java. After lots of searching I came across one link in MS forums which gives a code snippet to invoke MS Dynamics CRM 2011 WS from Java.
Consuming CRM REST Service from Java
However, it does not provide much details other than an account creation step. Using this code snippet I am able to create accounts. However, I want to also use the same REST web service to retrieve accounts, create new case request, add case request to account, etc. Based on .NET examples available online I am trying to use the service.createAccountQuery() method to retrieve accounts. However, while all .NET examples uses LINQ to setup search criteria, I am clueless how to specify the subpath string in java to retrieve existing Accounts by their name/city/country etc.
Appreciate any help.
回答1:
Instead of the "Account act..." line and below, use something like:
// Retrieve all accounts that the user has read access to.
string fetch1 = @"<fetch mapping=""logical"">
<entity name=""account"">
<all-attributes/>
</entity>
</fetch>";
// Fetch the results.
ExecuteFetchRequest req = new ExecuteFetchRequest();
req.FetchXml = fetch1;
ExecuteFetchResponse result1 = (ExecuteFetchResponse)service.Execute(req);
I'm unfamiliar with this proxy, but you want to call service.X where X is the Execute or RetrieveMultiple (based on what the proxy provides).
回答2:
not sure if you are still looking but for anyone else looking. I had the same issue.
It is using the odata query url so the subpath is the entitySet (e.g. for account it would be AccountSet)
you can then set the filter using the .filter method and the select via the .select method.
I did notice that you can't seem to do these on seperate lines though
e.g. you can't do
Query<microsoft.crm.sdk.data.services.Account> q = service.createAccountQuery("AccountSet");
q.filter("substringof('Test',Name)");
q.select("AccountId,Name");
q.execute();
you must do
Query<microsoft.crm.sdk.data.services.Account> q = service.createAccountQuery("AccountSet").filter("substringof('Test',Name)").select("AccountId,Name");
q.execute();
Chris
来源:https://stackoverflow.com/questions/11014275/connect-ms-dynamics-crm-2011-from-java